annotate hotspot/src/share/vm/utilities/utf8.hpp @ 46545:b970b6e40209

8181450: assert in BasicHashtable::verify_table Summary: remove assert as it has small probability of happening and added logging Reviewed-by: kbarrett, sspitsyn
author coleenp
date Fri, 16 Jun 2017 09:13:56 -0400
parents 287c4ebd11b0
children
rev   line source
duke@1 1 /*
thartmann@33628 2 * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
duke@1 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@1 4 *
duke@1 5 * This code is free software; you can redistribute it and/or modify it
duke@1 6 * under the terms of the GNU General Public License version 2 only, as
duke@1 7 * published by the Free Software Foundation.
duke@1 8 *
duke@1 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@1 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@1 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@1 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@1 13 * accompanied this code).
duke@1 14 *
duke@1 15 * You should have received a copy of the GNU General Public License version
duke@1 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@1 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@1 18 *
trims@5547 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@5547 20 * or visit www.oracle.com if you need additional information or have any
trims@5547 21 * questions.
duke@1 22 *
duke@1 23 */
duke@1 24
stefank@7397 25 #ifndef SHARE_VM_UTILITIES_UTF8_HPP
stefank@7397 26 #define SHARE_VM_UTILITIES_UTF8_HPP
stefank@7397 27
stefank@7397 28 #include "memory/allocation.hpp"
stefank@7397 29
duke@1 30 // Low-level interface for UTF8 strings
duke@1 31
duke@1 32 class UTF8 : AllStatic {
duke@1 33 public:
minqi@14477 34 // returns the unicode length of a 0-terminated utf8 string
thartmann@33628 35 static int unicode_length(const char* utf8_str) {
thartmann@33628 36 bool is_latin1, has_multibyte;
thartmann@33628 37 return unicode_length(utf8_str, is_latin1, has_multibyte);
thartmann@33628 38 }
thartmann@33628 39 static int unicode_length(const char* utf8_str, bool& is_latin1, bool& has_multibyte);
duke@1 40
minqi@14477 41 // returns the unicode length of a non-0-terminated utf8 string
thartmann@33628 42 static int unicode_length(const char* utf8_str, int len) {
thartmann@33628 43 bool is_latin1, has_multibyte;
thartmann@33628 44 return unicode_length(utf8_str, len, is_latin1, has_multibyte);
thartmann@33628 45 }
thartmann@33628 46 static int unicode_length(const char* utf8_str, int len, bool& is_latin1, bool& has_multibyte);
duke@1 47
minqi@14477 48 // converts a utf8 string to a unicode string
thartmann@33628 49 template<typename T> static void convert_to_unicode(const char* utf8_str, T* unicode_str, int unicode_length);
duke@1 50
minqi@14477 51 // returns the quoted ascii length of a utf8 string
minqi@14477 52 static int quoted_ascii_length(const char* utf8_str, int utf8_length);
minqi@14477 53
minqi@14477 54 // converts a utf8 string to quoted ascii
iklam@16602 55 static void as_quoted_ascii(const char* utf8_str, int utf8_length, char* buf, int buflen);
minqi@14477 56
minqi@14477 57 // converts a quoted ascii string to utf8 string. returns the original
minqi@14477 58 // string unchanged if nothing needs to be done.
minqi@14477 59 static const char* from_quoted_ascii(const char* quoted_ascii_string);
minqi@14477 60
duke@1 61 // decodes the current utf8 character, stores the result in value,
minqi@14477 62 // and returns the end of the current utf8 chararacter.
thartmann@33628 63 template<typename T> static char* next(const char* str, T* value);
duke@1 64
duke@1 65 // decodes the current utf8 character, gets the supplementary character instead of
duke@1 66 // the surrogate pair when seeing a supplementary character in string,
minqi@14477 67 // stores the result in value, and returns the end of the current utf8 chararacter.
duke@1 68 static char* next_character(const char* str, jint* value);
duke@1 69
duke@1 70 // Utility methods
coleenp@8076 71 static const jbyte* strrchr(const jbyte* base, int length, jbyte c);
coleenp@8076 72 static bool equal(const jbyte* base1, int length1, const jbyte* base2,int length2);
duke@1 73 static bool is_supplementary_character(const unsigned char* str);
duke@1 74 static jint get_supplementary_character(const unsigned char* str);
alanb@36508 75
alanb@36508 76 static bool is_legal_utf8(const unsigned char* buffer, int length,
alanb@36508 77 bool version_leq_47);
duke@1 78 };
duke@1 79
duke@1 80
duke@1 81 // Low-level interface for UNICODE strings
duke@1 82
duke@1 83 // A unicode string represents a string in the UTF-16 format in which supplementary
duke@1 84 // characters are represented by surrogate pairs. Index values refer to char code
duke@1 85 // units, so a supplementary character uses two positions in a unicode string.
duke@1 86
duke@1 87 class UNICODE : AllStatic {
duke@1 88 public:
thartmann@33628 89 // checks if the given unicode character can be encoded as latin1
thartmann@33628 90 static bool is_latin1(jchar c);
thartmann@33628 91
thartmann@33628 92 // checks if the given string can be encoded as latin1
thartmann@33628 93 static bool is_latin1(jchar* base, int length);
thartmann@33628 94
duke@1 95 // returns the utf8 size of a unicode character
duke@1 96 static int utf8_size(jchar c);
thartmann@33628 97 static int utf8_size(jbyte c);
duke@1 98
duke@1 99 // returns the utf8 length of a unicode string
thartmann@42057 100 template<typename T> static int utf8_length(T* base, int length);
duke@1 101
duke@1 102 // converts a unicode string to utf8 string
duke@1 103 static void convert_to_utf8(const jchar* base, int length, char* utf8_buffer);
duke@1 104
duke@1 105 // converts a unicode string to a utf8 string; result is allocated
thartmann@42057 106 // in resource area unless a buffer is provided. The unicode 'length'
thartmann@42057 107 // parameter is set to the length of the result utf8 string.
thartmann@42057 108 template<typename T> static char* as_utf8(T* base, int& length);
duke@1 109 static char* as_utf8(jchar* base, int length, char* buf, int buflen);
thartmann@33628 110 static char* as_utf8(jbyte* base, int length, char* buf, int buflen);
minqi@14477 111
minqi@14477 112 // returns the quoted ascii length of a unicode string
thartmann@33628 113 template<typename T> static int quoted_ascii_length(T* base, int length);
minqi@14477 114
thartmann@33628 115 // converts a unicode string to quoted ascii
thartmann@33628 116 template<typename T> static void as_quoted_ascii(const T* base, int length, char* buf, int buflen);
duke@1 117 };
stefank@7397 118
stefank@7397 119 #endif // SHARE_VM_UTILITIES_UTF8_HPP