p += 4;
if (njs_fast_path(njs_surrogate_trailing(utf_low))) {
- utf = njs_string_surrogate_pair(utf, utf_low);
+ utf = njs_surrogate_pair(utf, utf_low);
} else if (njs_surrogate_leading(utf_low)) {
utf = NJS_UNICODE_REPLACEMENT;
if (cp_pair != 0) {
if (njs_fast_path(njs_surrogate_trailing(cp))) {
- cp = njs_string_surrogate_pair(cp_pair, cp);
+ cp = njs_surrogate_pair(cp_pair, cp);
} else if (njs_slow_path(njs_surrogate_leading(cp))) {
cp = NJS_UNICODE_REPLACEMENT;
if (cp_pair != 0) {
if (njs_fast_path(njs_surrogate_trailing(cp))) {
- cp = njs_string_surrogate_pair(cp_pair, cp);
+ cp = njs_surrogate_pair(cp_pair, cp);
} else if (njs_slow_path(njs_surrogate_leading(cp))) {
cp = NJS_UNICODE_REPLACEMENT;
goto uri_error;
}
- cp = njs_string_surrogate_pair(cp, cp_low);
+ cp = njs_surrogate_pair(cp, cp_low);
size += njs_utf8_size(cp) * 3;
continue;
}
if (njs_slow_path(njs_surrogate_leading(cp))) {
cp_low = njs_utf8_decode(&ctx, &src, end);
- cp = njs_string_surrogate_pair(cp, cp_low);
+ cp = njs_surrogate_pair(cp, cp_low);
}
njs_utf8_encode(encode, cp);
/* The maximum signed int32_t. */
#define NJS_STRING_MAX_LENGTH 0x7fffffff
-#define njs_surrogate_leading(cp) ((cp) >= 0xd800 && (cp) <= 0xdbff)
-
-#define njs_surrogate_trailing(cp) ((cp) >= 0xdc00 && (cp) <= 0xdfff)
-
-#define njs_surrogate_any(cp) ((cp) >= 0xd800 && (cp) <= 0xdfff)
-
-/* Converting surrogate pair to code point. */
-#define njs_string_surrogate_pair(high, low) \
- (0x10000 + ((high - 0xd800) << 10) + (low - 0xdc00))
-
/*
* NJS_STRING_MAP_STRIDE should be power of two to use shift and binary
* AND operations instead of division and remainder operations but no
u_char upper;
} njs_unicode_decode_t;
+#define njs_surrogate_leading(cp) \
+ (((unsigned) (cp) - 0xd800) <= 0xdbff - 0xd800)
+
+#define njs_surrogate_trailing(cp) \
+ (((unsigned) (cp) - 0xdc00) <= 0xdfff - 0xdc00)
+
+#define njs_surrogate_any(cp) \
+ (((unsigned) (cp) - 0xd800) <= 0xdfff - 0xd800)
+
+#define njs_surrogate_pair(high, low) \
+ (0x10000 + (((high) - 0xd800) << 10) + ((low) - 0xdc00))
+
#endif /* _NJS_UNICODE_H_INCLUDED_ */
#endif
if (ctx->codepoint != 0x00) {
- if ((unsigned) (unit - 0xDC00) <= (0xDFFF - 0xDC00)) {
- unit = 0x10000 + ((ctx->codepoint - 0xD800) << 10)
- + (unit - 0xDC00);
+ if (njs_surrogate_trailing(unit)) {
+ unit = njs_surrogate_pair(ctx->codepoint, unit);
ctx->codepoint = 0x00;
return NJS_UNICODE_ERROR;
}
- /* Surrogate pair. */
-
- if ((unsigned) (unit - 0xD800) <= (0xDFFF - 0xD800)) {
- if ((unsigned) (unit - 0xDC00) <= (0xDFFF - 0xDC00)) {
+ if (njs_surrogate_any(unit)) {
+ if (njs_surrogate_trailing(unit)) {
return NJS_UNICODE_ERROR;
}