duke@435: /* duke@435: * Copyright 1997-2005 Sun Microsystems, Inc. All Rights Reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * duke@435: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, duke@435: * CA 95054 USA or visit www.sun.com if you need additional information or duke@435: * have any questions. duke@435: * duke@435: */ duke@435: duke@435: # include "incls/_precompiled.incl" duke@435: # include "incls/_symbolOop.cpp.incl" duke@435: duke@435: bool symbolOopDesc::equals(const char* str, int len) const { duke@435: int l = utf8_length(); duke@435: if (l != len) return false; duke@435: while (l-- > 0) { duke@435: if (str[l] != (char) byte_at(l)) duke@435: return false; duke@435: } duke@435: assert(l == -1, "we should be at the beginning"); duke@435: return true; duke@435: } duke@435: duke@435: char* symbolOopDesc::as_C_string(char* buf, int size) const { duke@435: if (size > 0) { duke@435: int len = MIN2(size - 1, utf8_length()); duke@435: for (int i = 0; i < len; i++) { duke@435: buf[i] = byte_at(i); duke@435: } duke@435: buf[len] = '\0'; duke@435: } duke@435: return buf; duke@435: } duke@435: duke@435: char* symbolOopDesc::as_C_string() const { duke@435: int len = utf8_length(); duke@435: char* str = NEW_RESOURCE_ARRAY(char, len + 1); duke@435: return as_C_string(str, len + 1); duke@435: } duke@435: duke@435: char* symbolOopDesc::as_C_string_flexible_buffer(Thread* t, duke@435: char* buf, int size) const { duke@435: char* str; duke@435: int len = utf8_length(); duke@435: int buf_len = len + 1; duke@435: if (size < buf_len) { duke@435: str = NEW_RESOURCE_ARRAY(char, buf_len); duke@435: } else { duke@435: str = buf; duke@435: } duke@435: return as_C_string(str, buf_len); duke@435: } duke@435: duke@435: void symbolOopDesc::print_symbol_on(outputStream* st) { duke@435: st = st ? st : tty; duke@435: for (int index = 0; index < utf8_length(); index++) duke@435: st->put((char)byte_at(index)); duke@435: } duke@435: duke@435: jchar* symbolOopDesc::as_unicode(int& length) const { duke@435: symbolOopDesc* this_ptr = (symbolOopDesc*)this; duke@435: length = UTF8::unicode_length((char*)this_ptr->bytes(), utf8_length()); duke@435: jchar* result = NEW_RESOURCE_ARRAY(jchar, length); duke@435: if (length > 0) { duke@435: UTF8::convert_to_unicode((char*)this_ptr->bytes(), result, length); duke@435: } duke@435: return result; duke@435: } duke@435: duke@435: const char* symbolOopDesc::as_klass_external_name(char* buf, int size) const { duke@435: if (size > 0) { duke@435: char* str = as_C_string(buf, size); duke@435: int length = (int)strlen(str); duke@435: // Turn all '/'s into '.'s (also for array klasses) duke@435: for (int index = 0; index < length; index++) { duke@435: if (str[index] == '/') { duke@435: str[index] = '.'; duke@435: } duke@435: } duke@435: return str; duke@435: } else { duke@435: return buf; duke@435: } duke@435: } duke@435: duke@435: const char* symbolOopDesc::as_klass_external_name() const { duke@435: char* str = as_C_string(); duke@435: int length = (int)strlen(str); duke@435: // Turn all '/'s into '.'s (also for array klasses) duke@435: for (int index = 0; index < length; index++) { duke@435: if (str[index] == '/') { duke@435: str[index] = '.'; duke@435: } duke@435: } duke@435: return str; duke@435: }