author | ppunegov |
Wed, 17 Aug 2016 18:48:34 +0300 | |
changeset 41335 | 27115e2e42cc |
parent 37466 | 287c4ebd11b0 |
child 42057 | 6a5b8ebcd3f2 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
33628 | 2 |
* Copyright (c) 1997, 2015, 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 |
||
7397 | 25 |
#ifndef SHARE_VM_UTILITIES_UTF8_HPP |
26 |
#define SHARE_VM_UTILITIES_UTF8_HPP |
|
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 |
|
95e66ea71f71
6830717: replay of compilations would help with debugging
minqi
parents:
8921
diff
changeset
|
57 |
// 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
|
58 |
// string unchanged if nothing needs to be done. |
95e66ea71f71
6830717: replay of compilations would help with debugging
minqi
parents:
8921
diff
changeset
|
59 |
static const char* from_quoted_ascii(const char* quoted_ascii_string); |
95e66ea71f71
6830717: replay of compilations would help with debugging
minqi
parents:
8921
diff
changeset
|
60 |
|
1 | 61 |
// 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
|
62 |
// and returns the end of the current utf8 chararacter. |
33628 | 63 |
template<typename T> static char* next(const char* str, T* value); |
1 | 64 |
|
65 |
// decodes the current utf8 character, gets the supplementary character instead of |
|
66 |
// 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
|
67 |
// stores the result in value, and returns the end of the current utf8 chararacter. |
1 | 68 |
static char* next_character(const char* str, jint* value); |
69 |
||
70 |
// Utility methods |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
71 |
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
|
72 |
static bool equal(const jbyte* base1, int length1, const jbyte* base2,int length2); |
1 | 73 |
static bool is_supplementary_character(const unsigned char* str); |
74 |
static jint get_supplementary_character(const unsigned char* str); |
|
36508 | 75 |
|
76 |
static bool is_legal_utf8(const unsigned char* buffer, int length, |
|
77 |
bool version_leq_47); |
|
1 | 78 |
}; |
79 |
||
80 |
||
81 |
// Low-level interface for UNICODE strings |
|
82 |
||
83 |
// A unicode string represents a string in the UTF-16 format in which supplementary |
|
84 |
// characters are represented by surrogate pairs. Index values refer to char code |
|
85 |
// units, so a supplementary character uses two positions in a unicode string. |
|
86 |
||
87 |
class UNICODE : AllStatic { |
|
88 |
public: |
|
33628 | 89 |
// checks if the given unicode character can be encoded as latin1 |
90 |
static bool is_latin1(jchar c); |
|
91 |
||
92 |
// checks if the given string can be encoded as latin1 |
|
93 |
static bool is_latin1(jchar* base, int length); |
|
94 |
||
1 | 95 |
// returns the utf8 size of a unicode character |
96 |
static int utf8_size(jchar c); |
|
33628 | 97 |
static int utf8_size(jbyte c); |
1 | 98 |
|
99 |
// returns the utf8 length of a unicode string |
|
100 |
static int utf8_length(jchar* base, int length); |
|
33628 | 101 |
static int utf8_length(jbyte* base, int length); |
1 | 102 |
|
103 |
// converts a unicode string to utf8 string |
|
104 |
static void convert_to_utf8(const jchar* base, int length, char* utf8_buffer); |
|
105 |
||
106 |
// converts a unicode string to a utf8 string; result is allocated |
|
107 |
// in resource area unless a buffer is provided. |
|
108 |
static char* as_utf8(jchar* base, int length); |
|
33628 | 109 |
static char* as_utf8(jbyte* base, int length); |
1 | 110 |
static char* as_utf8(jchar* base, int length, char* buf, int buflen); |
33628 | 111 |
static char* as_utf8(jbyte* base, int length, char* buf, int buflen); |
14477
95e66ea71f71
6830717: replay of compilations would help with debugging
minqi
parents:
8921
diff
changeset
|
112 |
|
95e66ea71f71
6830717: replay of compilations would help with debugging
minqi
parents:
8921
diff
changeset
|
113 |
// returns the quoted ascii length of a unicode string |
33628 | 114 |
template<typename T> static int quoted_ascii_length(T* base, int length); |
14477
95e66ea71f71
6830717: replay of compilations would help with debugging
minqi
parents:
8921
diff
changeset
|
115 |
|
33628 | 116 |
// converts a unicode string to quoted ascii |
117 |
template<typename T> static void as_quoted_ascii(const T* base, int length, char* buf, int buflen); |
|
1 | 118 |
}; |
7397 | 119 |
|
120 |
#endif // SHARE_VM_UTILITIES_UTF8_HPP |