diff options
author | Michael Wright <michaelwr@google.com> | 2016-05-09 14:43:31 +0100 |
---|---|---|
committer | Michael Wright <michaelwr@google.com> | 2016-05-09 19:45:07 +0100 |
commit | 5bacef33c91e9625dfd09ecf638c2de7faecd34e (patch) | |
tree | 545ac749f183ec37edc89eb5e2066427cc0457fa /libutils/Unicode.cpp | |
parent | ea41a18c933d20264b89fc89febf387231dc0c24 (diff) | |
download | system_core-5bacef33c91e9625dfd09ecf638c2de7faecd34e.tar.gz system_core-5bacef33c91e9625dfd09ecf638c2de7faecd34e.tar.bz2 system_core-5bacef33c91e9625dfd09ecf638c2de7faecd34e.zip |
Add String16#contains and strstr16 methods.
These are needed for aapt to find javadoc comments that contain
"@removed" in order to skip them when printing styleable docs.
Bug: 28663748
Change-Id: I8866d2167c41e11d6c2586da369560d5815fd13e
Diffstat (limited to 'libutils/Unicode.cpp')
-rw-r--r-- | libutils/Unicode.cpp | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/libutils/Unicode.cpp b/libutils/Unicode.cpp index 6f4b72176..ade896a02 100644 --- a/libutils/Unicode.cpp +++ b/libutils/Unicode.cpp @@ -222,11 +222,16 @@ int strncmp16(const char16_t *s1, const char16_t *s2, size_t n) char16_t ch; int d = 0; - while ( n-- ) { + if (n == 0) { + return 0; + } + + do { d = (int)(ch = *s1++) - (int)*s2++; - if ( d || !ch ) + if ( d || !ch ) { break; - } + } + } while (--n); return d; } @@ -284,6 +289,24 @@ size_t strnlen16(const char16_t *s, size_t maxlen) return ss-s; } +char16_t* strstr16(const char16_t* src, const char16_t* target) +{ + const char16_t needle = *target++; + if (needle != '\0') { + do { + do { + if (*src == '\0') { + return nullptr; + } + } while (*src++ != needle); + } while (strcmp16(src, target) != 0); + src--; + } + + return (char16_t*)src; +} + + int strzcmp16(const char16_t *s1, size_t n1, const char16_t *s2, size_t n2) { const char16_t* e1 = s1+n1; |