1 /******************************************************************** 2 * COPYRIGHT: 3 * Copyright (c) 2008-2010, International Business Machines Corporation and 4 * others. All Rights Reserved. 5 ********************************************************************/ 6 // 7 // file: regextxt.cpp 8 // 9 // This file contains utility code for supporting UText in the regular expression engine. 10 // 11 12 #include "regextxt.h" 13 14 U_NAMESPACE_BEGIN 15 16 U_CFUNC UChar U_CALLCONV 17 uregex_utext_unescape_charAt(int32_t offset, void *ct) { 18 struct URegexUTextUnescapeCharContext *context = (struct URegexUTextUnescapeCharContext *)ct; 19 UChar32 c; 20 if (offset == context->lastOffset + 1) { 21 c = UTEXT_NEXT32(context->text); 22 context->lastOffset++; 23 } else if (offset == context->lastOffset) { 24 c = UTEXT_PREVIOUS32(context->text); 25 UTEXT_NEXT32(context->text); 26 } else { 27 utext_moveIndex32(context->text, offset - context->lastOffset - 1); 28 c = UTEXT_NEXT32(context->text); 29 context->lastOffset = offset; 30 } 31 32 // !!!: Doesn't handle characters outside BMP 33 if (U_IS_BMP(c)) { 34 return (UChar)c; 35 } else { 36 return 0; 37 } 38 } 39 40 U_CFUNC UChar U_CALLCONV 41 uregex_ucstr_unescape_charAt(int32_t offset, void *context) { 42 return ((UChar *)context)[offset]; 43 } 44 45 U_NAMESPACE_END 46