1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/intl/icu/source/common/unisetspan.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,155 @@ 1.4 +/* 1.5 +****************************************************************************** 1.6 +* 1.7 +* Copyright (C) 2007, International Business Machines 1.8 +* Corporation and others. All Rights Reserved. 1.9 +* 1.10 +****************************************************************************** 1.11 +* file name: unisetspan.h 1.12 +* encoding: US-ASCII 1.13 +* tab size: 8 (not used) 1.14 +* indentation:4 1.15 +* 1.16 +* created on: 2007mar01 1.17 +* created by: Markus W. Scherer 1.18 +*/ 1.19 + 1.20 +#ifndef __UNISETSPAN_H__ 1.21 +#define __UNISETSPAN_H__ 1.22 + 1.23 +#include "unicode/utypes.h" 1.24 +#include "unicode/uniset.h" 1.25 + 1.26 +U_NAMESPACE_BEGIN 1.27 + 1.28 +/* 1.29 + * Implement span() etc. for a set with strings. 1.30 + * Avoid recursion because of its exponential complexity. 1.31 + * Instead, try multiple paths at once and track them with an IndexList. 1.32 + */ 1.33 +class UnicodeSetStringSpan : public UMemory { 1.34 +public: 1.35 + /* 1.36 + * Which span() variant will be used? 1.37 + * The object is either built for one variant and used once, 1.38 + * or built for all and may be used many times. 1.39 + */ 1.40 + enum { 1.41 + FWD = 0x20, 1.42 + BACK = 0x10, 1.43 + UTF16 = 8, 1.44 + UTF8 = 4, 1.45 + CONTAINED = 2, 1.46 + NOT_CONTAINED = 1, 1.47 + 1.48 + ALL = 0x3f, 1.49 + 1.50 + FWD_UTF16_CONTAINED = FWD | UTF16 | CONTAINED, 1.51 + FWD_UTF16_NOT_CONTAINED = FWD | UTF16 | NOT_CONTAINED, 1.52 + FWD_UTF8_CONTAINED = FWD | UTF8 | CONTAINED, 1.53 + FWD_UTF8_NOT_CONTAINED = FWD | UTF8 | NOT_CONTAINED, 1.54 + BACK_UTF16_CONTAINED = BACK | UTF16 | CONTAINED, 1.55 + BACK_UTF16_NOT_CONTAINED= BACK | UTF16 | NOT_CONTAINED, 1.56 + BACK_UTF8_CONTAINED = BACK | UTF8 | CONTAINED, 1.57 + BACK_UTF8_NOT_CONTAINED = BACK | UTF8 | NOT_CONTAINED 1.58 + }; 1.59 + 1.60 + UnicodeSetStringSpan(const UnicodeSet &set, const UVector &setStrings, uint32_t which); 1.61 + 1.62 + // Copy constructor. Assumes which==ALL for a frozen set. 1.63 + UnicodeSetStringSpan(const UnicodeSetStringSpan &otherStringSpan, const UVector &newParentSetStrings); 1.64 + 1.65 + ~UnicodeSetStringSpan(); 1.66 + 1.67 + /* 1.68 + * Do the strings need to be checked in span() etc.? 1.69 + * @return TRUE if strings need to be checked (call span() here), 1.70 + * FALSE if not (use a BMPSet for best performance). 1.71 + */ 1.72 + inline UBool needsStringSpanUTF16(); 1.73 + inline UBool needsStringSpanUTF8(); 1.74 + 1.75 + // For fast UnicodeSet::contains(c). 1.76 + inline UBool contains(UChar32 c) const; 1.77 + 1.78 + int32_t span(const UChar *s, int32_t length, USetSpanCondition spanCondition) const; 1.79 + 1.80 + int32_t spanBack(const UChar *s, int32_t length, USetSpanCondition spanCondition) const; 1.81 + 1.82 + int32_t spanUTF8(const uint8_t *s, int32_t length, USetSpanCondition spanCondition) const; 1.83 + 1.84 + int32_t spanBackUTF8(const uint8_t *s, int32_t length, USetSpanCondition spanCondition) const; 1.85 + 1.86 +private: 1.87 + // Special spanLength byte values. 1.88 + enum { 1.89 + // The spanLength is >=0xfe. 1.90 + LONG_SPAN=0xfe, 1.91 + // All code points in the string are contained in the parent set. 1.92 + ALL_CP_CONTAINED=0xff 1.93 + }; 1.94 + 1.95 + // Add a starting or ending string character to the spanNotSet 1.96 + // so that a character span ends before any string. 1.97 + void addToSpanNotSet(UChar32 c); 1.98 + 1.99 + int32_t spanNot(const UChar *s, int32_t length) const; 1.100 + int32_t spanNotBack(const UChar *s, int32_t length) const; 1.101 + int32_t spanNotUTF8(const uint8_t *s, int32_t length) const; 1.102 + int32_t spanNotBackUTF8(const uint8_t *s, int32_t length) const; 1.103 + 1.104 + // Set for span(). Same as parent but without strings. 1.105 + UnicodeSet spanSet; 1.106 + 1.107 + // Set for span(not contained). 1.108 + // Same as spanSet, plus characters that start or end strings. 1.109 + UnicodeSet *pSpanNotSet; 1.110 + 1.111 + // The strings of the parent set. 1.112 + const UVector &strings; 1.113 + 1.114 + // Pointer to the UTF-8 string lengths. 1.115 + // Also pointer to further allocated storage for meta data and 1.116 + // UTF-8 string contents as necessary. 1.117 + int32_t *utf8Lengths; 1.118 + 1.119 + // Pointer to the part of the (utf8Lengths) memory block that stores 1.120 + // the lengths of span(), spanBack() etc. for each string. 1.121 + uint8_t *spanLengths; 1.122 + 1.123 + // Pointer to the part of the (utf8Lengths) memory block that stores 1.124 + // the UTF-8 versions of the parent set's strings. 1.125 + uint8_t *utf8; 1.126 + 1.127 + // Number of bytes for all UTF-8 versions of strings together. 1.128 + int32_t utf8Length; 1.129 + 1.130 + // Maximum lengths of relevant strings. 1.131 + int32_t maxLength16; 1.132 + int32_t maxLength8; 1.133 + 1.134 + // Set up for all variants of span()? 1.135 + UBool all; 1.136 + 1.137 + // Memory for small numbers and lengths of strings. 1.138 + // For example, for 8 strings: 1.139 + // 8 UTF-8 lengths, 8*4 bytes span lengths, 8*2 3-byte UTF-8 characters 1.140 + // = 112 bytes = int32_t[28]. 1.141 + int32_t staticLengths[32]; 1.142 +}; 1.143 + 1.144 +UBool UnicodeSetStringSpan::needsStringSpanUTF16() { 1.145 + return (UBool)(maxLength16!=0); 1.146 +} 1.147 + 1.148 +UBool UnicodeSetStringSpan::needsStringSpanUTF8() { 1.149 + return (UBool)(maxLength8!=0); 1.150 +} 1.151 + 1.152 +UBool UnicodeSetStringSpan::contains(UChar32 c) const { 1.153 + return spanSet.contains(c); 1.154 +} 1.155 + 1.156 +U_NAMESPACE_END 1.157 + 1.158 +#endif