michael@0: /******************************************************************** michael@0: * COPYRIGHT: michael@0: * Copyright (c) 2008-2011, International Business Machines Corporation and michael@0: * others. All Rights Reserved. michael@0: ********************************************************************/ michael@0: // michael@0: // file: regextxt.cpp michael@0: // michael@0: // This file contains utility code for supporting UText in the regular expression engine. michael@0: // michael@0: michael@0: #include "unicode/utf.h" michael@0: #include "regextxt.h" michael@0: michael@0: U_NAMESPACE_BEGIN michael@0: michael@0: U_CFUNC UChar U_CALLCONV michael@0: uregex_utext_unescape_charAt(int32_t offset, void *ct) { michael@0: struct URegexUTextUnescapeCharContext *context = (struct URegexUTextUnescapeCharContext *)ct; michael@0: UChar32 c; michael@0: if (offset == context->lastOffset + 1) { michael@0: c = UTEXT_NEXT32(context->text); michael@0: context->lastOffset++; michael@0: } else if (offset == context->lastOffset) { michael@0: c = UTEXT_PREVIOUS32(context->text); michael@0: UTEXT_NEXT32(context->text); michael@0: } else { michael@0: utext_moveIndex32(context->text, offset - context->lastOffset - 1); michael@0: c = UTEXT_NEXT32(context->text); michael@0: context->lastOffset = offset; michael@0: } michael@0: michael@0: // !!!: Doesn't handle characters outside BMP michael@0: if (U_IS_BMP(c)) { michael@0: return (UChar)c; michael@0: } else { michael@0: return 0; michael@0: } michael@0: } michael@0: michael@0: U_CFUNC UChar U_CALLCONV michael@0: uregex_ucstr_unescape_charAt(int32_t offset, void *context) { michael@0: return ((UChar *)context)[offset]; michael@0: } michael@0: michael@0: U_NAMESPACE_END