Jungshik Shin | 87232d8 | 2017-05-13 21:10:13 -0700 | [diff] [blame] | 1 | // © 2016 and later: Unicode, Inc. and others. |
Jungshik Shin | 5feb9ad | 2016-10-21 12:52:48 -0700 | [diff] [blame] | 2 | // License & terms of use: http://www.unicode.org/copyright.html |
jshin@chromium.org | 6f31ac3 | 2014-03-26 22:15:14 +0000 | [diff] [blame] | 3 | /* |
| 4 | ******************************************************************************* |
| 5 | * Copyright (C) 2011, International Business Machines |
| 6 | * Corporation and others. All Rights Reserved. |
| 7 | ******************************************************************************* |
| 8 | * file name: patternprops.h |
Jungshik Shin | 87232d8 | 2017-05-13 21:10:13 -0700 | [diff] [blame] | 9 | * encoding: UTF-8 |
jshin@chromium.org | 6f31ac3 | 2014-03-26 22:15:14 +0000 | [diff] [blame] | 10 | * tab size: 8 (not used) |
| 11 | * indentation:4 |
| 12 | * |
| 13 | * created on: 2011mar13 |
| 14 | * created by: Markus W. Scherer |
| 15 | */ |
| 16 | |
| 17 | #ifndef __PATTERNPROPS_H__ |
| 18 | #define __PATTERNPROPS_H__ |
| 19 | |
Frank Tang | 69c72a6 | 2019-04-03 21:41:21 -0700 | [diff] [blame] | 20 | #include "unicode/unistr.h" |
jshin@chromium.org | 6f31ac3 | 2014-03-26 22:15:14 +0000 | [diff] [blame] | 21 | #include "unicode/utypes.h" |
| 22 | |
| 23 | U_NAMESPACE_BEGIN |
| 24 | |
| 25 | /** |
| 26 | * Implements the immutable Unicode properties Pattern_Syntax and Pattern_White_Space. |
| 27 | * Hardcodes these properties, does not load data, does not depend on other ICU classes. |
| 28 | * <p> |
| 29 | * Note: Both properties include ASCII as well as non-ASCII, non-Latin-1 code points, |
| 30 | * and both properties only include BMP code points (no supplementary ones). |
| 31 | * Pattern_Syntax includes some unassigned code points. |
| 32 | * <p> |
| 33 | * [:Pattern_White_Space:] = |
| 34 | * [\u0009-\u000D\ \u0085\u200E\u200F\u2028\u2029] |
| 35 | * <p> |
| 36 | * [:Pattern_Syntax:] = |
| 37 | * [!-/\:-@\[-\^`\{-~\u00A1-\u00A7\u00A9\u00AB\u00AC\u00AE |
| 38 | * \u00B0\u00B1\u00B6\u00BB\u00BF\u00D7\u00F7 |
| 39 | * \u2010-\u2027\u2030-\u203E\u2041-\u2053\u2055-\u205E |
| 40 | * \u2190-\u245F\u2500-\u2775\u2794-\u2BFF\u2E00-\u2E7F |
| 41 | * \u3001-\u3003\u3008-\u3020\u3030\uFD3E\uFD3F\uFE45\uFE46] |
| 42 | * @author mscherer |
| 43 | */ |
| 44 | class U_COMMON_API PatternProps { |
| 45 | public: |
| 46 | /** |
Frank Tang | f90543d | 2020-10-30 19:02:04 -0700 | [diff] [blame] | 47 | * @return true if c is a Pattern_Syntax code point. |
jshin@chromium.org | 6f31ac3 | 2014-03-26 22:15:14 +0000 | [diff] [blame] | 48 | */ |
| 49 | static UBool isSyntax(UChar32 c); |
| 50 | |
| 51 | /** |
Frank Tang | f90543d | 2020-10-30 19:02:04 -0700 | [diff] [blame] | 52 | * @return true if c is a Pattern_Syntax or Pattern_White_Space code point. |
jshin@chromium.org | 6f31ac3 | 2014-03-26 22:15:14 +0000 | [diff] [blame] | 53 | */ |
| 54 | static UBool isSyntaxOrWhiteSpace(UChar32 c); |
| 55 | |
| 56 | /** |
Frank Tang | f90543d | 2020-10-30 19:02:04 -0700 | [diff] [blame] | 57 | * @return true if c is a Pattern_White_Space character. |
jshin@chromium.org | 6f31ac3 | 2014-03-26 22:15:14 +0000 | [diff] [blame] | 58 | */ |
| 59 | static UBool isWhiteSpace(UChar32 c); |
| 60 | |
| 61 | /** |
| 62 | * Skips over Pattern_White_Space starting at s. |
| 63 | * @return The smallest pointer at or after s with a non-white space character. |
| 64 | */ |
| 65 | static const UChar *skipWhiteSpace(const UChar *s, int32_t length); |
| 66 | |
| 67 | /** |
Frank Tang | 69c72a6 | 2019-04-03 21:41:21 -0700 | [diff] [blame] | 68 | * Skips over Pattern_White_Space starting at index start in s. |
| 69 | * @return The smallest index at or after start with a non-white space character. |
| 70 | */ |
| 71 | static int32_t skipWhiteSpace(const UnicodeString &s, int32_t start); |
| 72 | |
| 73 | /** |
jshin@chromium.org | 6f31ac3 | 2014-03-26 22:15:14 +0000 | [diff] [blame] | 74 | * @return s except with leading and trailing Pattern_White_Space removed and length adjusted. |
| 75 | */ |
| 76 | static const UChar *trimWhiteSpace(const UChar *s, int32_t &length); |
| 77 | |
| 78 | /** |
| 79 | * Tests whether the string contains a "pattern identifier", that is, |
| 80 | * whether it contains only non-Pattern_White_Space, non-Pattern_Syntax characters. |
Frank Tang | f90543d | 2020-10-30 19:02:04 -0700 | [diff] [blame] | 81 | * @return true if there are no Pattern_White_Space or Pattern_Syntax characters in s. |
jshin@chromium.org | 6f31ac3 | 2014-03-26 22:15:14 +0000 | [diff] [blame] | 82 | */ |
| 83 | static UBool isIdentifier(const UChar *s, int32_t length); |
| 84 | |
| 85 | /** |
| 86 | * Skips over a "pattern identifier" starting at index s. |
| 87 | * @return The smallest pointer at or after s with |
| 88 | * a Pattern_White_Space or Pattern_Syntax character. |
| 89 | */ |
| 90 | static const UChar *skipIdentifier(const UChar *s, int32_t length); |
| 91 | |
| 92 | private: |
Frank Tang | 1f164ee | 2022-11-08 12:31:27 -0800 | [diff] [blame^] | 93 | PatternProps() = delete; // no constructor: all static methods |
jshin@chromium.org | 6f31ac3 | 2014-03-26 22:15:14 +0000 | [diff] [blame] | 94 | }; |
| 95 | |
| 96 | U_NAMESPACE_END |
| 97 | |
| 98 | #endif // __PATTERNPROPS_H__ |