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
17U_NAMESPACE_BEGIN
18
19U_CFUNC UChar U_CALLCONV
20uregex_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
43U_CFUNC UChar U_CALLCONV
44uregex_ucstr_unescape_charAt(int32_t offset, void *context) {
45 return ((UChar *)context)[offset];
46}
47
48U_NAMESPACE_END
49