comparison src/share/vm/oops/symbolOop.cpp @ 0:a61af66fc99e jdk7-b24

Initial load
author duke
date Sat, 01 Dec 2007 00:00:00 +0000
parents
children 2a1a77d3458f
comparison
equal deleted inserted replaced
-1:000000000000 0:a61af66fc99e
1 /*
2 * Copyright 1997-2005 Sun Microsystems, Inc. All Rights Reserved.
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 *
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 *
23 */
24
25 # include "incls/_precompiled.incl"
26 # include "incls/_symbolOop.cpp.incl"
27
28 bool symbolOopDesc::equals(const char* str, int len) const {
29 int l = utf8_length();
30 if (l != len) return false;
31 while (l-- > 0) {
32 if (str[l] != (char) byte_at(l))
33 return false;
34 }
35 assert(l == -1, "we should be at the beginning");
36 return true;
37 }
38
39 char* symbolOopDesc::as_C_string(char* buf, int size) const {
40 if (size > 0) {
41 int len = MIN2(size - 1, utf8_length());
42 for (int i = 0; i < len; i++) {
43 buf[i] = byte_at(i);
44 }
45 buf[len] = '\0';
46 }
47 return buf;
48 }
49
50 char* symbolOopDesc::as_C_string() const {
51 int len = utf8_length();
52 char* str = NEW_RESOURCE_ARRAY(char, len + 1);
53 return as_C_string(str, len + 1);
54 }
55
56 char* symbolOopDesc::as_C_string_flexible_buffer(Thread* t,
57 char* buf, int size) const {
58 char* str;
59 int len = utf8_length();
60 int buf_len = len + 1;
61 if (size < buf_len) {
62 str = NEW_RESOURCE_ARRAY(char, buf_len);
63 } else {
64 str = buf;
65 }
66 return as_C_string(str, buf_len);
67 }
68
69 void symbolOopDesc::print_symbol_on(outputStream* st) {
70 st = st ? st : tty;
71 for (int index = 0; index < utf8_length(); index++)
72 st->put((char)byte_at(index));
73 }
74
75 jchar* symbolOopDesc::as_unicode(int& length) const {
76 symbolOopDesc* this_ptr = (symbolOopDesc*)this;
77 length = UTF8::unicode_length((char*)this_ptr->bytes(), utf8_length());
78 jchar* result = NEW_RESOURCE_ARRAY(jchar, length);
79 if (length > 0) {
80 UTF8::convert_to_unicode((char*)this_ptr->bytes(), result, length);
81 }
82 return result;
83 }
84
85 const char* symbolOopDesc::as_klass_external_name(char* buf, int size) const {
86 if (size > 0) {
87 char* str = as_C_string(buf, size);
88 int length = (int)strlen(str);
89 // Turn all '/'s into '.'s (also for array klasses)
90 for (int index = 0; index < length; index++) {
91 if (str[index] == '/') {
92 str[index] = '.';
93 }
94 }
95 return str;
96 } else {
97 return buf;
98 }
99 }
100
101 const char* symbolOopDesc::as_klass_external_name() const {
102 char* str = as_C_string();
103 int length = (int)strlen(str);
104 // Turn all '/'s into '.'s (also for array klasses)
105 for (int index = 0; index < length; index++) {
106 if (str[index] == '/') {
107 str[index] = '.';
108 }
109 }
110 return str;
111 }