| 1 | // © 2016 and later: Unicode, Inc. and others. |
| 2 | // License & terms of use: http://www.unicode.org/copyright.html |
| 3 | /* |
| 4 | ******************************************************************************* |
| 5 | * Copyright (C) 2010-2012, International Business Machines |
| 6 | * Corporation and others. All Rights Reserved. |
| 7 | ******************************************************************************* |
| 8 | * file name: udicttrie.h |
| 9 | * encoding: UTF-8 |
| 10 | * tab size: 8 (not used) |
| 11 | * indentation:4 |
| 12 | * |
| 13 | * created on: 2010dec17 |
| 14 | * created by: Markus W. Scherer |
| 15 | */ |
| 16 | |
| 17 | #ifndef __USTRINGTRIE_H__ |
| 18 | #define __USTRINGTRIE_H__ |
| 19 | |
| 20 | /** |
| 21 | * \file |
| 22 | * \brief C API: Helper definitions for dictionary trie APIs. |
| 23 | */ |
| 24 | |
| 25 | #include "unicode/utypes.h" |
| 26 | |
| 27 | |
| 28 | /** |
| 29 | * Return values for BytesTrie::next(), UCharsTrie::next() and similar methods. |
| 30 | * @see USTRINGTRIE_MATCHES |
| 31 | * @see USTRINGTRIE_HAS_VALUE |
| 32 | * @see USTRINGTRIE_HAS_NEXT |
| 33 | * @stable ICU 4.8 |
| 34 | */ |
| 35 | enum UStringTrieResult { |
| 36 | /** |
| 37 | * The input unit(s) did not continue a matching string. |
| 38 | * Once current()/next() return USTRINGTRIE_NO_MATCH, |
| 39 | * all further calls to current()/next() will also return USTRINGTRIE_NO_MATCH, |
| 40 | * until the trie is reset to its original state or to a saved state. |
| 41 | * @stable ICU 4.8 |
| 42 | */ |
| 43 | USTRINGTRIE_NO_MATCH, |
| 44 | /** |
| 45 | * The input unit(s) continued a matching string |
| 46 | * but there is no value for the string so far. |
| 47 | * (It is a prefix of a longer string.) |
| 48 | * @stable ICU 4.8 |
| 49 | */ |
| 50 | USTRINGTRIE_NO_VALUE, |
| 51 | /** |
| 52 | * The input unit(s) continued a matching string |
| 53 | * and there is a value for the string so far. |
| 54 | * This value will be returned by getValue(). |
| 55 | * No further input byte/unit can continue a matching string. |
| 56 | * @stable ICU 4.8 |
| 57 | */ |
| 58 | USTRINGTRIE_FINAL_VALUE, |
| 59 | /** |
| 60 | * The input unit(s) continued a matching string |
| 61 | * and there is a value for the string so far. |
| 62 | * This value will be returned by getValue(). |
| 63 | * Another input byte/unit can continue a matching string. |
| 64 | * @stable ICU 4.8 |
| 65 | */ |
| 66 | USTRINGTRIE_INTERMEDIATE_VALUE |
| 67 | }; |
| 68 | |
| 69 | /** |
| 70 | * Same as (result!=USTRINGTRIE_NO_MATCH). |
| 71 | * @param result A result from BytesTrie::first(), UCharsTrie::next() etc. |
| 72 | * @return true if the input bytes/units so far are part of a matching string/byte sequence. |
| 73 | * @stable ICU 4.8 |
| 74 | */ |
| 75 | #define USTRINGTRIE_MATCHES(result) ((result)!=USTRINGTRIE_NO_MATCH) |
| 76 | |
| 77 | /** |
| 78 | * Equivalent to (result==USTRINGTRIE_INTERMEDIATE_VALUE || result==USTRINGTRIE_FINAL_VALUE) but |
| 79 | * this macro evaluates result exactly once. |
| 80 | * @param result A result from BytesTrie::first(), UCharsTrie::next() etc. |
| 81 | * @return true if there is a value for the input bytes/units so far. |
| 82 | * @see BytesTrie::getValue |
| 83 | * @see UCharsTrie::getValue |
| 84 | * @stable ICU 4.8 |
| 85 | */ |
| 86 | #define USTRINGTRIE_HAS_VALUE(result) ((result)>=USTRINGTRIE_FINAL_VALUE) |
| 87 | |
| 88 | /** |
| 89 | * Equivalent to (result==USTRINGTRIE_NO_VALUE || result==USTRINGTRIE_INTERMEDIATE_VALUE) but |
| 90 | * this macro evaluates result exactly once. |
| 91 | * @param result A result from BytesTrie::first(), UCharsTrie::next() etc. |
| 92 | * @return true if another input byte/unit can continue a matching string. |
| 93 | * @stable ICU 4.8 |
| 94 | */ |
| 95 | #define USTRINGTRIE_HAS_NEXT(result) ((result)&1) |
| 96 | |
| 97 | #endif /* __USTRINGTRIE_H__ */ |
| 98 | |