0N/A/*
2273N/A * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
1879N/A#ifndef SHARE_VM_UTILITIES_UTF8_HPP
1879N/A#define SHARE_VM_UTILITIES_UTF8_HPP
1879N/A
1879N/A#include "memory/allocation.hpp"
1879N/A#include "utilities/top.hpp"
1879N/A
0N/A// Low-level interface for UTF8 strings
0N/A
0N/Aclass UTF8 : AllStatic {
0N/A public:
0N/A // returns the unicode length of a 0-terminated uft8 string
0N/A static int unicode_length(const char* uft8_str);
0N/A
0N/A // returns the unicode length of a non-0-terminated uft8 string
0N/A static int unicode_length(const char* uft8_str, int len);
0N/A
0N/A // converts a uft8 string to a unicode string
0N/A static void convert_to_unicode(const char* utf8_str, jchar* unicode_buffer, int unicode_length);
0N/A
0N/A // decodes the current utf8 character, stores the result in value,
0N/A // and returns the end of the current uft8 chararacter.
0N/A static char* next(const char* str, jchar* value);
0N/A
0N/A // decodes the current utf8 character, gets the supplementary character instead of
0N/A // the surrogate pair when seeing a supplementary character in string,
0N/A // stores the result in value, and returns the end of the current uft8 chararacter.
0N/A static char* next_character(const char* str, jint* value);
0N/A
0N/A // Utility methods
2062N/A static const jbyte* strrchr(const jbyte* base, int length, jbyte c);
2062N/A static bool equal(const jbyte* base1, int length1, const jbyte* base2,int length2);
0N/A static bool is_supplementary_character(const unsigned char* str);
0N/A static jint get_supplementary_character(const unsigned char* str);
0N/A};
0N/A
0N/A
0N/A// Low-level interface for UNICODE strings
0N/A
0N/A// A unicode string represents a string in the UTF-16 format in which supplementary
0N/A// characters are represented by surrogate pairs. Index values refer to char code
0N/A// units, so a supplementary character uses two positions in a unicode string.
0N/A
0N/Aclass UNICODE : AllStatic {
0N/A public:
0N/A // returns the utf8 size of a unicode character
0N/A static int utf8_size(jchar c);
0N/A
0N/A // returns the utf8 length of a unicode string
0N/A static int utf8_length(jchar* base, int length);
0N/A
0N/A // converts a unicode string to utf8 string
0N/A static void convert_to_utf8(const jchar* base, int length, char* utf8_buffer);
0N/A
0N/A // converts a unicode string to a utf8 string; result is allocated
0N/A // in resource area unless a buffer is provided.
0N/A static char* as_utf8(jchar* base, int length);
0N/A static char* as_utf8(jchar* base, int length, char* buf, int buflen);
0N/A};
1879N/A
1879N/A#endif // SHARE_VM_UTILITIES_UTF8_HPP