regextxt.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. #include "unicode/utf.h"
  14. #include "regextxt.h"
  15. U_NAMESPACE_BEGIN
  16. U_CFUNC char16_t 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. // !!!: Doesn't handle characters outside BMP
  32. if (U_IS_BMP(c)) {
  33. return (char16_t)c;
  34. } else {
  35. return 0;
  36. }
  37. }
  38. U_CFUNC char16_t U_CALLCONV
  39. uregex_ucstr_unescape_charAt(int32_t offset, void *context) {
  40. return ((char16_t *)context)[offset];
  41. }
  42. U_NAMESPACE_END