|
9 | 9 | import org.jabref.logic.layout.LayoutFormatter; |
10 | 10 | import org.jabref.model.entry.AuthorList; |
11 | 11 |
|
12 | | -/** |
13 | | - * This layout formatter uses the Bibtex name.format$ method and provides ultimate flexibility: |
14 | | - * <p> |
15 | | - * The formatter needs a parameter to be passed in that follows the following format: |
16 | | - * |
17 | | - * <code><case1>@<range11>@"<format>"@<range12>@"<format>"@<range13>...@@ |
18 | | - * <p> |
19 | | - * <case2>@<range21>@...</code> and so on. |
20 | | - * <p> |
21 | | - * Individual cases are separated by @@ and items in a case by @. |
22 | | - * <p> |
23 | | - * Cases are just integers or the character * and will tell the formatter to apply the following formats if there are |
24 | | - * less or equal authors given to it. The cases must be in strict increasing order with the * in the last position. |
25 | | - * <p> |
26 | | - * For instance: |
27 | | - * <p> |
28 | | - * case1 = 2 |
29 | | - * case2 = 3 |
30 | | - * case3 = * |
31 | | - * <p> |
32 | | - * Ranges are either <integer>..<integer>, <integer> or the character * using a 1 based index for indexing |
33 | | - * authors from the given authorlist. Integer indexes can be negative to denote them to start from |
34 | | - * the end of the list where -1 is the last author. |
35 | | - * <p> |
36 | | - * For instance with an authorlist of "Joe Doe and Mary Jane and Bruce Bar and Arthur Kay": |
37 | | - * <p> |
38 | | - * 1..3 will affect Joe, Mary and Bruce |
39 | | - * <p> |
40 | | - * 4..4 will affect Arthur |
41 | | - * <p> |
42 | | - * * will affect all of them |
43 | | - * <p> |
44 | | - * 2..-1 will affect Mary, Bruce and Arthur |
45 | | - * <p> |
46 | | - * The <format> uses the Bibtex formatter format: |
47 | | - * <p> |
48 | | - * The four letter v, f, l, j indicate the name parts von, first, last, jr which |
49 | | - * are used within curly braces. A single letter v, f, l, j indicates that the name should be abbreviated. |
50 | | - * To put a quote in the format string quote it using \" (mh. this doesn't work yet) |
51 | | - * <p> |
52 | | - * I give some examples but would rather point you to the bibtex documentation. |
53 | | - * <p> |
54 | | - * "{ll}, {f}." Will turn "Joe Doe" into "Doe, J." |
55 | | - * <p> |
56 | | - * Complete example: |
57 | | - * <p> |
58 | | - * To turn: |
59 | | - * <p> |
60 | | - * "Joe Doe and Mary Jane and Bruce Bar and Arthur Kay" |
61 | | - * <p> |
62 | | - * into |
63 | | - * <p> |
64 | | - * "Doe, J., Jane, M., Bar, B. and Kay, A." |
65 | | - * <p> |
66 | | - * you would use |
67 | | - * <p> |
68 | | - * 1@*@{ll}, {f}.@@2@1@{ll}, {f}.@2@ and {ll}, {f}.@@*@1..-3@{ll}, {f}., @-2@{ll}, {f}.@-1@ and {ll}, {f}. |
69 | | - * <p> |
70 | | - * Yeah this is trouble-some to write, but should work. |
71 | | - * <p> |
72 | | - * For more examples see the test-cases. |
73 | | - * |
74 | | - */ |
| 12 | +/// This layout formatter uses the BibTeX `name.format$` method and provides ultimate flexibility. |
| 13 | +/// |
| 14 | +/// The formatter needs a parameter with the following format: |
| 15 | +/// |
| 16 | +/// ``` |
| 17 | +/// <case1>@<range11>@"<format>"@<range12>@"<format>"@<range13>...@@ |
| 18 | +/// <case2>@<range21>@... |
| 19 | +///``` |
| 20 | +/// |
| 21 | +/// Individual cases are separated by `@@` and items in a case by `@`. |
| 22 | +/// |
| 23 | +/// Cases are just integers or the character `*` and tell the formatter to apply the following formats |
| 24 | +/// if there are less or equal authors given. |
| 25 | +/// The cases must be in strictly increasing order with `*` in the last position. |
| 26 | +/// |
| 27 | +/// Example: |
| 28 | +/// - `case1 = 2` |
| 29 | +/// - `case2 = 3` |
| 30 | +/// - `case3 = *` |
| 31 | +/// |
| 32 | +/// Ranges are either `<integer>..<integer>`, `<integer>` or `*` (using a 1-based index). |
| 33 | +/// Negative integers start from the end (`-1` = last author). |
| 34 | +/// |
| 35 | +/// Example with `Joe Doe and Mary Jane and Bruce Bar and Arthur Kay`: |
| 36 | +/// - `1..3` → Joe, Mary, Bruce |
| 37 | +/// - `4..4` → Arthur |
| 38 | +/// - `*` → all authors |
| 39 | +/// - `2..-1` → Mary, Bruce, Arthur |
| 40 | +/// |
| 41 | +/// The `<format>` uses the BibTeX formatter syntax: |
| 42 | +/// - The letters `v`, `f`, `l`, `j` indicate name parts (von, first, last, jr). Use them inside `{}` for full form. |
| 43 | +/// - A single letter (`v`, `f`, `l`, `j`) abbreviates the part. |
| 44 | +/// - Quotes must be escaped as `\"` (not fully supported yet). |
| 45 | +/// |
| 46 | +/// Example: |
| 47 | +/// - `"{ll},{f}."` → `"Joe Doe"` becomes `"Doe, J."` |
| 48 | +/// |
| 49 | +/// Complete example: |
| 50 | +/// |
| 51 | +/// Input: |
| 52 | +/// ``` |
| 53 | +/// Joe Doe and Mary Jane and Bruce Bar and Arthur Kay |
| 54 | +///``` |
| 55 | +/// |
| 56 | +/// Output: |
| 57 | +/// ``` |
| 58 | +/// Doe, J., Jane, M., Bar, B. and Kay, A. |
| 59 | +///``` |
| 60 | +/// |
| 61 | +/// Formatter parameter: |
| 62 | +/// ``` |
| 63 | +/// 1@*@{ll},{f}.@@2@1@{ll},{f}.@2@ and {ll},{f}.@@*@1..-3@{ll},{f}., @-2@{ll},{f}.@-1@ and {ll},{f}. |
| 64 | +///``` |
| 65 | +/// |
| 66 | +/// This is troublesome to write, but it works. |
| 67 | +/// For more examples see the test cases. |
75 | 68 | public class NameFormatter implements LayoutFormatter { |
76 | 69 |
|
77 | 70 | public static final String DEFAULT_FORMAT = "1@*@{ff }{vv }{ll}{, jj}@@*@1@{ff }{vv }{ll}{, jj}@*@, {ff }{vv }{ll}{, jj}"; |
|
0 commit comments