1 /********************************************************************
2  * COPYRIGHT:
3  * Copyright (c) 2008-2011, 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 "unicode/utf.h"
13 #include "regextxt.h"
14 
15 U_NAMESPACE_BEGIN
16 
17 U_CFUNC UChar U_CALLCONV
uregex_utext_unescape_charAt(int32_t offset,void * ct)18 uregex_utext_unescape_charAt(int32_t offset, void *ct) {
19     struct URegexUTextUnescapeCharContext *context = (struct URegexUTextUnescapeCharContext *)ct;
20     UChar32 c;
21     if (offset == context->lastOffset + 1) {
22         c = UTEXT_NEXT32(context->text);
23         context->lastOffset++;
24     } else if (offset == context->lastOffset) {
25         c = UTEXT_PREVIOUS32(context->text);
26         UTEXT_NEXT32(context->text);
27     } else {
28         utext_moveIndex32(context->text, offset - context->lastOffset - 1);
29         c = UTEXT_NEXT32(context->text);
30         context->lastOffset = offset;
31     }
32 
33     // !!!: Doesn't handle characters outside BMP
34     if (U_IS_BMP(c)) {
35         return (UChar)c;
36     } else {
37         return 0;
38     }
39 }
40 
41 U_CFUNC UChar U_CALLCONV
uregex_ucstr_unescape_charAt(int32_t offset,void * context)42 uregex_ucstr_unescape_charAt(int32_t offset, void *context) {
43     return ((UChar *)context)[offset];
44 }
45 
46 U_NAMESPACE_END
47