2007-12-01 00:00:00 +00:00
|
|
|
/*
|
8141132: JEP 254: Compact Strings
Adopt a more space-efficient internal representation for strings.
Co-authored-by: Brent Christian <brent.christian@oracle.com>
Co-authored-by: Vivek Deshpande <vivek.r.deshpande@intel.com>
Co-authored-by: Charlie Hunt <charlie.hunt@oracle.com>
Co-authored-by: Vladimir Kozlov <vladimir.kozlov@oracle.com>
Co-authored-by: Roger Riggs <roger.riggs@oracle.com>
Co-authored-by: Xueming Shen <xueming.shen@oracle.com>
Co-authored-by: Aleksey Shipilev <aleksey.shipilev@oracle.com>
Co-authored-by: Sandhya Viswanathan <sandhya.viswanathan@intel.com>
Reviewed-by: alanb, bdelsart, coleenp, iklam, jiangli, jrose, kevinw, naoto, pliden, roland, smarks, twisti
2015-11-03 09:41:03 +01:00
|
|
|
* Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
|
2007-12-01 00:00:00 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
*
|
|
|
|
* This code is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 only, as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* version 2 for more details (a copy is included in the LICENSE file that
|
|
|
|
* accompanied this code).
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License version
|
|
|
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
2010-05-27 19:08:38 -07:00
|
|
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
|
|
* or visit www.oracle.com if you need additional information or have any
|
|
|
|
* questions.
|
2007-12-01 00:00:00 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2010-11-23 13:22:55 -08:00
|
|
|
#ifndef SHARE_VM_UTILITIES_UTF8_HPP
|
|
|
|
#define SHARE_VM_UTILITIES_UTF8_HPP
|
|
|
|
|
|
|
|
#include "memory/allocation.hpp"
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
// Low-level interface for UTF8 strings
|
|
|
|
|
|
|
|
class UTF8 : AllStatic {
|
|
|
|
public:
|
2012-11-12 14:03:53 -08:00
|
|
|
// returns the unicode length of a 0-terminated utf8 string
|
8141132: JEP 254: Compact Strings
Adopt a more space-efficient internal representation for strings.
Co-authored-by: Brent Christian <brent.christian@oracle.com>
Co-authored-by: Vivek Deshpande <vivek.r.deshpande@intel.com>
Co-authored-by: Charlie Hunt <charlie.hunt@oracle.com>
Co-authored-by: Vladimir Kozlov <vladimir.kozlov@oracle.com>
Co-authored-by: Roger Riggs <roger.riggs@oracle.com>
Co-authored-by: Xueming Shen <xueming.shen@oracle.com>
Co-authored-by: Aleksey Shipilev <aleksey.shipilev@oracle.com>
Co-authored-by: Sandhya Viswanathan <sandhya.viswanathan@intel.com>
Reviewed-by: alanb, bdelsart, coleenp, iklam, jiangli, jrose, kevinw, naoto, pliden, roland, smarks, twisti
2015-11-03 09:41:03 +01:00
|
|
|
static int unicode_length(const char* utf8_str) {
|
|
|
|
bool is_latin1, has_multibyte;
|
|
|
|
return unicode_length(utf8_str, is_latin1, has_multibyte);
|
|
|
|
}
|
|
|
|
static int unicode_length(const char* utf8_str, bool& is_latin1, bool& has_multibyte);
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2012-11-12 14:03:53 -08:00
|
|
|
// returns the unicode length of a non-0-terminated utf8 string
|
8141132: JEP 254: Compact Strings
Adopt a more space-efficient internal representation for strings.
Co-authored-by: Brent Christian <brent.christian@oracle.com>
Co-authored-by: Vivek Deshpande <vivek.r.deshpande@intel.com>
Co-authored-by: Charlie Hunt <charlie.hunt@oracle.com>
Co-authored-by: Vladimir Kozlov <vladimir.kozlov@oracle.com>
Co-authored-by: Roger Riggs <roger.riggs@oracle.com>
Co-authored-by: Xueming Shen <xueming.shen@oracle.com>
Co-authored-by: Aleksey Shipilev <aleksey.shipilev@oracle.com>
Co-authored-by: Sandhya Viswanathan <sandhya.viswanathan@intel.com>
Reviewed-by: alanb, bdelsart, coleenp, iklam, jiangli, jrose, kevinw, naoto, pliden, roland, smarks, twisti
2015-11-03 09:41:03 +01:00
|
|
|
static int unicode_length(const char* utf8_str, int len) {
|
|
|
|
bool is_latin1, has_multibyte;
|
|
|
|
return unicode_length(utf8_str, len, is_latin1, has_multibyte);
|
|
|
|
}
|
|
|
|
static int unicode_length(const char* utf8_str, int len, bool& is_latin1, bool& has_multibyte);
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2012-11-12 14:03:53 -08:00
|
|
|
// converts a utf8 string to a unicode string
|
8141132: JEP 254: Compact Strings
Adopt a more space-efficient internal representation for strings.
Co-authored-by: Brent Christian <brent.christian@oracle.com>
Co-authored-by: Vivek Deshpande <vivek.r.deshpande@intel.com>
Co-authored-by: Charlie Hunt <charlie.hunt@oracle.com>
Co-authored-by: Vladimir Kozlov <vladimir.kozlov@oracle.com>
Co-authored-by: Roger Riggs <roger.riggs@oracle.com>
Co-authored-by: Xueming Shen <xueming.shen@oracle.com>
Co-authored-by: Aleksey Shipilev <aleksey.shipilev@oracle.com>
Co-authored-by: Sandhya Viswanathan <sandhya.viswanathan@intel.com>
Reviewed-by: alanb, bdelsart, coleenp, iklam, jiangli, jrose, kevinw, naoto, pliden, roland, smarks, twisti
2015-11-03 09:41:03 +01:00
|
|
|
template<typename T> static void convert_to_unicode(const char* utf8_str, T* unicode_str, int unicode_length);
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2012-11-12 14:03:53 -08:00
|
|
|
// returns the quoted ascii length of a utf8 string
|
|
|
|
static int quoted_ascii_length(const char* utf8_str, int utf8_length);
|
|
|
|
|
|
|
|
// converts a utf8 string to quoted ascii
|
2013-04-01 14:05:41 -07:00
|
|
|
static void as_quoted_ascii(const char* utf8_str, int utf8_length, char* buf, int buflen);
|
2012-11-12 14:03:53 -08:00
|
|
|
|
|
|
|
// converts a quoted ascii string to utf8 string. returns the original
|
|
|
|
// string unchanged if nothing needs to be done.
|
|
|
|
static const char* from_quoted_ascii(const char* quoted_ascii_string);
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
// decodes the current utf8 character, stores the result in value,
|
2012-11-12 14:03:53 -08:00
|
|
|
// and returns the end of the current utf8 chararacter.
|
8141132: JEP 254: Compact Strings
Adopt a more space-efficient internal representation for strings.
Co-authored-by: Brent Christian <brent.christian@oracle.com>
Co-authored-by: Vivek Deshpande <vivek.r.deshpande@intel.com>
Co-authored-by: Charlie Hunt <charlie.hunt@oracle.com>
Co-authored-by: Vladimir Kozlov <vladimir.kozlov@oracle.com>
Co-authored-by: Roger Riggs <roger.riggs@oracle.com>
Co-authored-by: Xueming Shen <xueming.shen@oracle.com>
Co-authored-by: Aleksey Shipilev <aleksey.shipilev@oracle.com>
Co-authored-by: Sandhya Viswanathan <sandhya.viswanathan@intel.com>
Reviewed-by: alanb, bdelsart, coleenp, iklam, jiangli, jrose, kevinw, naoto, pliden, roland, smarks, twisti
2015-11-03 09:41:03 +01:00
|
|
|
template<typename T> static char* next(const char* str, T* value);
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
// decodes the current utf8 character, gets the supplementary character instead of
|
|
|
|
// the surrogate pair when seeing a supplementary character in string,
|
2012-11-12 14:03:53 -08:00
|
|
|
// stores the result in value, and returns the end of the current utf8 chararacter.
|
2007-12-01 00:00:00 +00:00
|
|
|
static char* next_character(const char* str, jint* value);
|
|
|
|
|
|
|
|
// Utility methods
|
2011-01-27 16:11:27 -08:00
|
|
|
static const jbyte* strrchr(const jbyte* base, int length, jbyte c);
|
|
|
|
static bool equal(const jbyte* base1, int length1, const jbyte* base2,int length2);
|
2007-12-01 00:00:00 +00:00
|
|
|
static bool is_supplementary_character(const unsigned char* str);
|
|
|
|
static jint get_supplementary_character(const unsigned char* str);
|
8142968: Module System implementation
Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282
Co-authored-by: Alex Buckley <alex.buckley@oracle.com>
Co-authored-by: Jonathan Gibbons <jonathan.gibbons@oracle.com>
Co-authored-by: Karen Kinnear <karen.kinnear@oracle.com>
Co-authored-by: Mandy Chung <mandy.chung@oracle.com>
Co-authored-by: Mark Reinhold <mark.reinhold@oracle.com>
Co-authored-by: Harold Seigel <harold.seigel@oracle.com>
Co-authored-by: Lois Foltan <lois.foltan@oracle.com>
Co-authored-by: Calvin Cheung <calvin.cheung@oracle.com>
Co-authored-by: Christian Tornqvist <christian.tornqvist@oracle.com>
Co-authored-by: Erik Joelsson <erik.joelsson@oracle.com>
Co-authored-by: George Triantafillou <george.triantafillou@oracle.com>
Co-authored-by: Igor Ignatyev <igor.ignatyev@oracle.com>
Co-authored-by: Ioi Lam <ioi.lam@oracle.com>
Co-authored-by: James Laskey <james.laskey@oracle.com>
Co-authored-by: Jean-Francois Denise <jean-francois.denise@oracle.com>
Co-authored-by: Jiangli Zhou <jiangli.zhou@oracle.com>
Co-authored-by: Markus Gronlund <markus.gronlund@oracle.com>
Co-authored-by: Serguei Spitsyn <serguei.spitsyn@oracle.com>
Co-authored-by: Staffan Larsen <staffan.larsen@oracle.com>
Co-authored-by: Sundararajan Athijegannathan <sundararajan.athijegannathan@oracle.com>
Reviewed-by: acorn, ccheung, coleenp, ctornqvi, dholmes, dsimms, gtriantafill, iklam, jiangli, mgronlun, mseledtsov, cjplummer, sspitsyn, stefank, twisti, hseigel, lfoltan, alanb, mchung, dfazunen
2016-03-17 19:04:01 +00:00
|
|
|
|
|
|
|
static bool is_legal_utf8(const unsigned char* buffer, int length,
|
|
|
|
bool version_leq_47);
|
2007-12-01 00:00:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Low-level interface for UNICODE strings
|
|
|
|
|
|
|
|
// A unicode string represents a string in the UTF-16 format in which supplementary
|
|
|
|
// characters are represented by surrogate pairs. Index values refer to char code
|
|
|
|
// units, so a supplementary character uses two positions in a unicode string.
|
|
|
|
|
|
|
|
class UNICODE : AllStatic {
|
|
|
|
public:
|
8141132: JEP 254: Compact Strings
Adopt a more space-efficient internal representation for strings.
Co-authored-by: Brent Christian <brent.christian@oracle.com>
Co-authored-by: Vivek Deshpande <vivek.r.deshpande@intel.com>
Co-authored-by: Charlie Hunt <charlie.hunt@oracle.com>
Co-authored-by: Vladimir Kozlov <vladimir.kozlov@oracle.com>
Co-authored-by: Roger Riggs <roger.riggs@oracle.com>
Co-authored-by: Xueming Shen <xueming.shen@oracle.com>
Co-authored-by: Aleksey Shipilev <aleksey.shipilev@oracle.com>
Co-authored-by: Sandhya Viswanathan <sandhya.viswanathan@intel.com>
Reviewed-by: alanb, bdelsart, coleenp, iklam, jiangli, jrose, kevinw, naoto, pliden, roland, smarks, twisti
2015-11-03 09:41:03 +01:00
|
|
|
// checks if the given unicode character can be encoded as latin1
|
|
|
|
static bool is_latin1(jchar c);
|
|
|
|
|
|
|
|
// checks if the given string can be encoded as latin1
|
|
|
|
static bool is_latin1(jchar* base, int length);
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
// returns the utf8 size of a unicode character
|
|
|
|
static int utf8_size(jchar c);
|
8141132: JEP 254: Compact Strings
Adopt a more space-efficient internal representation for strings.
Co-authored-by: Brent Christian <brent.christian@oracle.com>
Co-authored-by: Vivek Deshpande <vivek.r.deshpande@intel.com>
Co-authored-by: Charlie Hunt <charlie.hunt@oracle.com>
Co-authored-by: Vladimir Kozlov <vladimir.kozlov@oracle.com>
Co-authored-by: Roger Riggs <roger.riggs@oracle.com>
Co-authored-by: Xueming Shen <xueming.shen@oracle.com>
Co-authored-by: Aleksey Shipilev <aleksey.shipilev@oracle.com>
Co-authored-by: Sandhya Viswanathan <sandhya.viswanathan@intel.com>
Reviewed-by: alanb, bdelsart, coleenp, iklam, jiangli, jrose, kevinw, naoto, pliden, roland, smarks, twisti
2015-11-03 09:41:03 +01:00
|
|
|
static int utf8_size(jbyte c);
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
// returns the utf8 length of a unicode string
|
2016-10-26 14:36:05 +02:00
|
|
|
template<typename T> static int utf8_length(T* base, int length);
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
// converts a unicode string to utf8 string
|
|
|
|
static void convert_to_utf8(const jchar* base, int length, char* utf8_buffer);
|
|
|
|
|
|
|
|
// converts a unicode string to a utf8 string; result is allocated
|
2016-10-26 14:36:05 +02:00
|
|
|
// in resource area unless a buffer is provided. The unicode 'length'
|
|
|
|
// parameter is set to the length of the result utf8 string.
|
|
|
|
template<typename T> static char* as_utf8(T* base, int& length);
|
2007-12-01 00:00:00 +00:00
|
|
|
static char* as_utf8(jchar* base, int length, char* buf, int buflen);
|
8141132: JEP 254: Compact Strings
Adopt a more space-efficient internal representation for strings.
Co-authored-by: Brent Christian <brent.christian@oracle.com>
Co-authored-by: Vivek Deshpande <vivek.r.deshpande@intel.com>
Co-authored-by: Charlie Hunt <charlie.hunt@oracle.com>
Co-authored-by: Vladimir Kozlov <vladimir.kozlov@oracle.com>
Co-authored-by: Roger Riggs <roger.riggs@oracle.com>
Co-authored-by: Xueming Shen <xueming.shen@oracle.com>
Co-authored-by: Aleksey Shipilev <aleksey.shipilev@oracle.com>
Co-authored-by: Sandhya Viswanathan <sandhya.viswanathan@intel.com>
Reviewed-by: alanb, bdelsart, coleenp, iklam, jiangli, jrose, kevinw, naoto, pliden, roland, smarks, twisti
2015-11-03 09:41:03 +01:00
|
|
|
static char* as_utf8(jbyte* base, int length, char* buf, int buflen);
|
2012-11-12 14:03:53 -08:00
|
|
|
|
|
|
|
// returns the quoted ascii length of a unicode string
|
8141132: JEP 254: Compact Strings
Adopt a more space-efficient internal representation for strings.
Co-authored-by: Brent Christian <brent.christian@oracle.com>
Co-authored-by: Vivek Deshpande <vivek.r.deshpande@intel.com>
Co-authored-by: Charlie Hunt <charlie.hunt@oracle.com>
Co-authored-by: Vladimir Kozlov <vladimir.kozlov@oracle.com>
Co-authored-by: Roger Riggs <roger.riggs@oracle.com>
Co-authored-by: Xueming Shen <xueming.shen@oracle.com>
Co-authored-by: Aleksey Shipilev <aleksey.shipilev@oracle.com>
Co-authored-by: Sandhya Viswanathan <sandhya.viswanathan@intel.com>
Reviewed-by: alanb, bdelsart, coleenp, iklam, jiangli, jrose, kevinw, naoto, pliden, roland, smarks, twisti
2015-11-03 09:41:03 +01:00
|
|
|
template<typename T> static int quoted_ascii_length(T* base, int length);
|
2012-11-12 14:03:53 -08:00
|
|
|
|
8141132: JEP 254: Compact Strings
Adopt a more space-efficient internal representation for strings.
Co-authored-by: Brent Christian <brent.christian@oracle.com>
Co-authored-by: Vivek Deshpande <vivek.r.deshpande@intel.com>
Co-authored-by: Charlie Hunt <charlie.hunt@oracle.com>
Co-authored-by: Vladimir Kozlov <vladimir.kozlov@oracle.com>
Co-authored-by: Roger Riggs <roger.riggs@oracle.com>
Co-authored-by: Xueming Shen <xueming.shen@oracle.com>
Co-authored-by: Aleksey Shipilev <aleksey.shipilev@oracle.com>
Co-authored-by: Sandhya Viswanathan <sandhya.viswanathan@intel.com>
Reviewed-by: alanb, bdelsart, coleenp, iklam, jiangli, jrose, kevinw, naoto, pliden, roland, smarks, twisti
2015-11-03 09:41:03 +01:00
|
|
|
// converts a unicode string to quoted ascii
|
|
|
|
template<typename T> static void as_quoted_ascii(const T* base, int length, char* buf, int buflen);
|
2007-12-01 00:00:00 +00:00
|
|
|
};
|
2010-11-23 13:22:55 -08:00
|
|
|
|
|
|
|
#endif // SHARE_VM_UTILITIES_UTF8_HPP
|