1 /* GENERATED SOURCE. DO NOT MODIFY. */ 2 // © 2017 and later: Unicode, Inc. and others. 3 // License & terms of use: http://www.unicode.org/copyright.html#License 4 package ohos.global.icu.impl.number.parse; 5 6 import ohos.global.icu.impl.StringSegment; 7 8 /** 9 * The core interface implemented by all matchers used for number parsing. 10 * 11 * Given a string, there should NOT be more than one way to consume the string with the same matcher 12 * applied multiple times. If there is, the non-greedy parsing algorithm will be unhappy and may enter an 13 * exponential-time loop. For example, consider the "A Matcher" that accepts "any number of As". Given 14 * the string "AAAA", there are 2^N = 8 ways to apply the A Matcher to this string: you could have the A 15 * Matcher apply 4 times to each character; you could have it apply just once to all the characters; you 16 * could have it apply to the first 2 characters and the second 2 characters; and so on. A better version 17 * of the "A Matcher" would be for it to accept exactly one A, and allow the algorithm to run it 18 * repeatedly to consume a string of multiple As. The A Matcher can implement the Flexible interface 19 * below to signal that it can be applied multiple times in a row. 20 * 21 * @author sffc 22 * @hide exposed on OHOS 23 */ 24 public interface NumberParseMatcher { 25 26 /** 27 * Matchers can implement the Flexible interface to indicate that they are optional and can be run 28 * repeatedly. Used by SeriesMatcher, primarily in the context of IgnorablesMatcher. 29 * @hide exposed on OHOS 30 */ 31 public interface Flexible { 32 } 33 34 /** 35 * Runs this matcher starting at the beginning of the given StringSegment. If this matcher finds 36 * something interesting in the StringSegment, it should update the offset of the StringSegment 37 * corresponding to how many chars were matched. 38 * 39 * @param segment 40 * The StringSegment to match against. Matches always start at the beginning of the 41 * segment. The segment is guaranteed to contain at least one char. 42 * @param result 43 * The data structure to store results if the match succeeds. 44 * @return Whether this matcher thinks there may be more interesting chars beyond the end of the 45 * string segment. 46 */ match(StringSegment segment, ParsedNumber result)47 public boolean match(StringSegment segment, ParsedNumber result); 48 49 /** 50 * Performs a fast "smoke check" for whether or not this matcher could possibly match against the 51 * given string segment. The test should be as fast as possible but also as restrictive as possible. 52 * For example, matchers can maintain a UnicodeSet of all code points that count possibly start a 53 * match. Matchers should use the {@link StringSegment#startsWith} method in order to correctly 54 * handle case folding. 55 * 56 * @param segment 57 * The segment to check against. 58 * @return true if the matcher might be able to match against this segment; false if it definitely 59 * will not be able to match. 60 */ smokeTest(StringSegment segment)61 public boolean smokeTest(StringSegment segment); 62 63 /** 64 * Method called at the end of a parse, after all matchers have failed to consume any more chars. 65 * Allows a matcher to make final modifications to the result given the knowledge that no more 66 * matches are possible. 67 * 68 * @param result 69 * The data structure to store results. 70 */ postProcess(ParsedNumber result)71 public void postProcess(ParsedNumber result); 72 } 73