author | stefank |
Mon, 25 Nov 2019 12:33:15 +0100 | |
changeset 59252 | 623722a6aeb9 |
parent 53731 | ee45b48c9e4a |
permissions | -rw-r--r-- |
1 | 1 |
/* |
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
51823
diff
changeset
|
2 |
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved. |
1 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
51823
diff
changeset
|
25 |
#ifndef SHARE_UTILITIES_UTF8_HPP |
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
51823
diff
changeset
|
26 |
#define SHARE_UTILITIES_UTF8_HPP |
7397 | 27 |
|
28 |
#include "memory/allocation.hpp" |
|
29 |
||
1 | 30 |
// Low-level interface for UTF8 strings |
31 |
||
32 |
class UTF8 : AllStatic { |
|
33 |
public: |
|
14477
95e66ea71f71
6830717: replay of compilations would help with debugging
minqi
parents:
8921
diff
changeset
|
34 |
// returns the unicode length of a 0-terminated utf8 string |
33628 | 35 |
static int unicode_length(const char* utf8_str) { |
36 |
bool is_latin1, has_multibyte; |
|
37 |
return unicode_length(utf8_str, is_latin1, has_multibyte); |
|
38 |
} |
|
39 |
static int unicode_length(const char* utf8_str, bool& is_latin1, bool& has_multibyte); |
|
1 | 40 |
|
14477
95e66ea71f71
6830717: replay of compilations would help with debugging
minqi
parents:
8921
diff
changeset
|
41 |
// returns the unicode length of a non-0-terminated utf8 string |
33628 | 42 |
static int unicode_length(const char* utf8_str, int len) { |
43 |
bool is_latin1, has_multibyte; |
|
44 |
return unicode_length(utf8_str, len, is_latin1, has_multibyte); |
|
45 |
} |
|
46 |
static int unicode_length(const char* utf8_str, int len, bool& is_latin1, bool& has_multibyte); |
|
1 | 47 |
|
14477
95e66ea71f71
6830717: replay of compilations would help with debugging
minqi
parents:
8921
diff
changeset
|
48 |
// converts a utf8 string to a unicode string |
33628 | 49 |
template<typename T> static void convert_to_unicode(const char* utf8_str, T* unicode_str, int unicode_length); |
1 | 50 |
|
14477
95e66ea71f71
6830717: replay of compilations would help with debugging
minqi
parents:
8921
diff
changeset
|
51 |
// returns the quoted ascii length of a utf8 string |
95e66ea71f71
6830717: replay of compilations would help with debugging
minqi
parents:
8921
diff
changeset
|
52 |
static int quoted_ascii_length(const char* utf8_str, int utf8_length); |
95e66ea71f71
6830717: replay of compilations would help with debugging
minqi
parents:
8921
diff
changeset
|
53 |
|
95e66ea71f71
6830717: replay of compilations would help with debugging
minqi
parents:
8921
diff
changeset
|
54 |
// converts a utf8 string to quoted ascii |
16602
5df51d3bc550
8011048: Possible reading from unmapped memory in UTF8::as_quoted_ascii()
iklam
parents:
14477
diff
changeset
|
55 |
static void as_quoted_ascii(const char* utf8_str, int utf8_length, char* buf, int buflen); |
14477
95e66ea71f71
6830717: replay of compilations would help with debugging
minqi
parents:
8921
diff
changeset
|
56 |
|
53731 | 57 |
#ifndef PRODUCT |
14477
95e66ea71f71
6830717: replay of compilations would help with debugging
minqi
parents:
8921
diff
changeset
|
58 |
// converts a quoted ascii string to utf8 string. returns the original |
95e66ea71f71
6830717: replay of compilations would help with debugging
minqi
parents:
8921
diff
changeset
|
59 |
// string unchanged if nothing needs to be done. |
95e66ea71f71
6830717: replay of compilations would help with debugging
minqi
parents:
8921
diff
changeset
|
60 |
static const char* from_quoted_ascii(const char* quoted_ascii_string); |
53731 | 61 |
#endif |
14477
95e66ea71f71
6830717: replay of compilations would help with debugging
minqi
parents:
8921
diff
changeset
|
62 |
|
1 | 63 |
// decodes the current utf8 character, stores the result in value, |
14477
95e66ea71f71
6830717: replay of compilations would help with debugging
minqi
parents:
8921
diff
changeset
|
64 |
// and returns the end of the current utf8 chararacter. |
33628 | 65 |
template<typename T> static char* next(const char* str, T* value); |
1 | 66 |
|
67 |
// decodes the current utf8 character, gets the supplementary character instead of |
|
68 |
// the surrogate pair when seeing a supplementary character in string, |
|
14477
95e66ea71f71
6830717: replay of compilations would help with debugging
minqi
parents:
8921
diff
changeset
|
69 |
// stores the result in value, and returns the end of the current utf8 chararacter. |
1 | 70 |
static char* next_character(const char* str, jint* value); |
71 |
||
72 |
// Utility methods |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
73 |
static const jbyte* strrchr(const jbyte* base, int length, jbyte c); |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
74 |
static bool equal(const jbyte* base1, int length1, const jbyte* base2,int length2); |
1 | 75 |
static bool is_supplementary_character(const unsigned char* str); |
76 |
static jint get_supplementary_character(const unsigned char* str); |
|
36508 | 77 |
|
78 |
static bool is_legal_utf8(const unsigned char* buffer, int length, |
|
79 |
bool version_leq_47); |
|
1 | 80 |
}; |
81 |
||
82 |
||
83 |
// Low-level interface for UNICODE strings |
|
84 |
||
85 |
// A unicode string represents a string in the UTF-16 format in which supplementary |
|
86 |
// characters are represented by surrogate pairs. Index values refer to char code |
|
87 |
// units, so a supplementary character uses two positions in a unicode string. |
|
88 |
||
89 |
class UNICODE : AllStatic { |
|
90 |
public: |
|
33628 | 91 |
// checks if the given unicode character can be encoded as latin1 |
92 |
static bool is_latin1(jchar c); |
|
93 |
||
94 |
// checks if the given string can be encoded as latin1 |
|
51823 | 95 |
static bool is_latin1(const jchar* base, int length); |
33628 | 96 |
|
1 | 97 |
// returns the utf8 size of a unicode character |
98 |
static int utf8_size(jchar c); |
|
33628 | 99 |
static int utf8_size(jbyte c); |
1 | 100 |
|
101 |
// returns the utf8 length of a unicode string |
|
51823 | 102 |
template<typename T> static int utf8_length(const T* base, int length); |
1 | 103 |
|
104 |
// converts a unicode string to utf8 string |
|
105 |
static void convert_to_utf8(const jchar* base, int length, char* utf8_buffer); |
|
106 |
||
107 |
// converts a unicode string to a utf8 string; result is allocated |
|
42057
6a5b8ebcd3f2
8164612: NoSuchMethodException when method name contains NULL or Latin-1 supplement character
thartmann
parents:
37466
diff
changeset
|
108 |
// in resource area unless a buffer is provided. The unicode 'length' |
6a5b8ebcd3f2
8164612: NoSuchMethodException when method name contains NULL or Latin-1 supplement character
thartmann
parents:
37466
diff
changeset
|
109 |
// parameter is set to the length of the result utf8 string. |
51823 | 110 |
template<typename T> static char* as_utf8(const T* base, int& length); |
111 |
static char* as_utf8(const jchar* base, int length, char* buf, int buflen); |
|
112 |
static char* as_utf8(const jbyte* base, int length, char* buf, int buflen); |
|
14477
95e66ea71f71
6830717: replay of compilations would help with debugging
minqi
parents:
8921
diff
changeset
|
113 |
|
95e66ea71f71
6830717: replay of compilations would help with debugging
minqi
parents:
8921
diff
changeset
|
114 |
// returns the quoted ascii length of a unicode string |
51823 | 115 |
template<typename T> static int quoted_ascii_length(const T* base, int length); |
14477
95e66ea71f71
6830717: replay of compilations would help with debugging
minqi
parents:
8921
diff
changeset
|
116 |
|
33628 | 117 |
// converts a unicode string to quoted ascii |
118 |
template<typename T> static void as_quoted_ascii(const T* base, int length, char* buf, int buflen); |
|
1 | 119 |
}; |
7397 | 120 |
|
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
51823
diff
changeset
|
121 |
#endif // SHARE_UTILITIES_UTF8_HPP |