1 #ifdef USE_PRAGMA_IDENT_SRC 2 #pragma ident "@(#)symbolOop.cpp 1.28 07/05/05 17:06:08 JVM" 3 #endif 4 /* 5 * Copyright 1997-2005 Sun Microsystems, Inc. All Rights Reserved. 6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 7 * 8 * This code is free software; you can redistribute it and/or modify it 9 * under the terms of the GNU General Public License version 2 only, as 10 * published by the Free Software Foundation. 11 * 12 * This code is distributed in the hope that it will be useful, but WITHOUT 13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15 * version 2 for more details (a copy is included in the LICENSE file that 16 * accompanied this code). 17 * 18 * You should have received a copy of the GNU General Public License version 19 * 2 along with this work; if not, write to the Free Software Foundation, 20 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 21 * 22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 23 * CA 95054 USA or visit www.sun.com if you need additional information or 24 * have any questions. 25 * 26 */ 27 28 # include "incls/_precompiled.incl" 29 # include "incls/_symbolOop.cpp.incl" 30 31 bool symbolOopDesc::equals(const char* str, int len) const { 32 int l = utf8_length(); 33 if (l != len) return false; 34 while (l-- > 0) { 35 if (str[l] != (char) byte_at(l)) 36 return false; 37 } 38 assert(l == -1, "we should be at the beginning"); 39 return true; 40 } 41 42 char* symbolOopDesc::as_C_string(char* buf, int size) const { 43 if (size > 0) { 44 int len = MIN2(size - 1, utf8_length()); 45 for (int i = 0; i < len; i++) { 46 buf[i] = byte_at(i); 47 } 48 buf[len] = '\0'; 49 } 50 return buf; 51 } 52 53 char* symbolOopDesc::as_C_string() const { 54 int len = utf8_length(); 55 char* str = NEW_RESOURCE_ARRAY(char, len + 1); 56 return as_C_string(str, len + 1); 57 } 58 59 char* symbolOopDesc::as_C_string_flexible_buffer(Thread* t, 60 char* buf, int size) const { 61 char* str; 62 int len = utf8_length(); 63 int buf_len = len + 1; 64 if (size < buf_len) { 65 str = NEW_RESOURCE_ARRAY(char, buf_len); 66 } else { 67 str = buf; 68 } 69 return as_C_string(str, buf_len); 70 } 71 72 void symbolOopDesc::print_symbol_on(outputStream* st) { 73 st = st ? st : tty; 74 int length = UTF8::unicode_length((const char*)bytes(), utf8_length()); 75 const char *ptr = (const char *)bytes(); 76 jchar value; 77 for (int index = 0; index < length; index++) { 78 ptr = UTF8::next(ptr, &value); 79 if (value >= 32 && value < 127 || value == '\'' || value == '\\') { 80 st->put(value); 81 } else { 82 st->print("\\u%04x", value); 83 } 84 } 85 } 86 87 jchar* symbolOopDesc::as_unicode(int& length) const { 88 symbolOopDesc* this_ptr = (symbolOopDesc*)this; 89 length = UTF8::unicode_length((char*)this_ptr->bytes(), utf8_length()); 90 jchar* result = NEW_RESOURCE_ARRAY(jchar, length); 91 if (length > 0) { 92 UTF8::convert_to_unicode((char*)this_ptr->bytes(), result, length); 93 } 94 return result; 95 } 96 97 const char* symbolOopDesc::as_klass_external_name(char* buf, int size) const { 98 if (size > 0) { 99 char* str = as_C_string(buf, size); 100 int length = (int)strlen(str); 101 // Turn all '/'s into '.'s (also for array klasses) 102 for (int index = 0; index < length; index++) { 103 if (str[index] == '/') { 104 str[index] = '.'; 105 } 106 } 107 return str; 108 } else { 109 return buf; 110 } 111 } 112 113 const char* symbolOopDesc::as_klass_external_name() const { 114 char* str = as_C_string(); 115 int length = (int)strlen(str); 116 // Turn all '/'s into '.'s (also for array klasses) 117 for (int index = 0; index < length; index++) { 118 if (str[index] == '/') { 119 str[index] = '.'; 120 } 121 } 122 return str; 123 }