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