| 1 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 2 | // Copyright (c) 2018 Saxonica Limited. |
| 3 | // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. |
| 4 | // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 5 | // This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0. |
| 6 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 7 | |
| 8 | package net.sf.saxon.expr.number; |
| 9 | |
| 10 | import net.sf.saxon.regex.UnicodeString; |
| 11 | import net.sf.saxon.tree.util.FastStringBuffer; |
| 12 | |
| 13 | import java.io.Serializable; |
| 14 | |
| 15 | /** |
| 16 | * A NumericGroupFormatter is responsible for insertion of grouping separators |
| 17 | * into a formatted number (for example, reformatting "1234" as "1,234"). |
| 18 | */ |
| 19 | |
| 20 | public abstract class NumericGroupFormatter { |
| 21 | |
| 22 | protected UnicodeString adjustedPicture; |
| 23 | |
| 24 | /** |
| 25 | * Get the adjusted (preprocessed) picture |
| 26 | * |
| 27 | * @return the adjusted picture |
| 28 | */ |
| 29 | |
| 30 | public UnicodeString getAdjustedPicture() { |
| 31 | return adjustedPicture; |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Reformat a number to add grouping separators |
| 36 | * |
| 37 | * @param value a buffer holding the number to be reformatted |
| 38 | * @return the reformatted number |
| 39 | */ |
| 40 | |
| 41 | public abstract String format(FastStringBuffer value); |
| 42 | |
| 43 | /** |
| 44 | * Get the grouping separator to be used, as a Unicode codepoint. If more than one is used, return the last. |
| 45 | * If no grouping separators are used, return null |
| 46 | * |
| 47 | * @return the grouping separator |
| 48 | */ |
| 49 | |
| 50 | /*@Nullable*/ |
| 51 | public abstract String getSeparator(); |
| 52 | } |
| 53 |