Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /*
2 * Copyright (c) 2008-2009 Mozilla Foundation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 * DEALINGS IN THE SOFTWARE.
21 */
23 package nu.validator.htmlparser.impl;
25 import nu.validator.htmlparser.annotation.Literal;
26 import nu.validator.htmlparser.annotation.Local;
27 import nu.validator.htmlparser.annotation.NoLength;
28 import nu.validator.htmlparser.common.Interner;
30 public final class Portability {
32 // Allocating methods
34 /**
35 * Allocates a new local name object. In C++, the refcount must be set up in such a way that
36 * calling <code>releaseLocal</code> on the return value balances the refcount set by this method.
37 */
38 public static @Local String newLocalNameFromBuffer(@NoLength char[] buf, int offset, int length, Interner interner) {
39 return new String(buf, offset, length).intern();
40 }
42 public static String newStringFromBuffer(@NoLength char[] buf, int offset, int length) {
43 return new String(buf, offset, length);
44 }
46 public static String newEmptyString() {
47 return "";
48 }
50 public static String newStringFromLiteral(@Literal String literal) {
51 return literal;
52 }
54 public static String newStringFromString(String string) {
55 return string;
56 }
58 // XXX get rid of this
59 public static char[] newCharArrayFromLocal(@Local String local) {
60 return local.toCharArray();
61 }
63 public static char[] newCharArrayFromString(String string) {
64 return string.toCharArray();
65 }
67 public static @Local String newLocalFromLocal(@Local String local, Interner interner) {
68 return local;
69 }
71 // Deallocation methods
73 public static void releaseString(String str) {
74 // No-op in Java
75 }
77 // Comparison methods
79 public static boolean localEqualsBuffer(@Local String local, @NoLength char[] buf, int offset, int length) {
80 if (local.length() != length) {
81 return false;
82 }
83 for (int i = 0; i < length; i++) {
84 if (local.charAt(i) != buf[offset + i]) {
85 return false;
86 }
87 }
88 return true;
89 }
91 public static boolean lowerCaseLiteralIsPrefixOfIgnoreAsciiCaseString(@Literal String lowerCaseLiteral,
92 String string) {
93 if (string == null) {
94 return false;
95 }
96 if (lowerCaseLiteral.length() > string.length()) {
97 return false;
98 }
99 for (int i = 0; i < lowerCaseLiteral.length(); i++) {
100 char c0 = lowerCaseLiteral.charAt(i);
101 char c1 = string.charAt(i);
102 if (c1 >= 'A' && c1 <= 'Z') {
103 c1 += 0x20;
104 }
105 if (c0 != c1) {
106 return false;
107 }
108 }
109 return true;
110 }
112 public static boolean lowerCaseLiteralEqualsIgnoreAsciiCaseString(@Literal String lowerCaseLiteral,
113 String string) {
114 if (string == null) {
115 return false;
116 }
117 if (lowerCaseLiteral.length() != string.length()) {
118 return false;
119 }
120 for (int i = 0; i < lowerCaseLiteral.length(); i++) {
121 char c0 = lowerCaseLiteral.charAt(i);
122 char c1 = string.charAt(i);
123 if (c1 >= 'A' && c1 <= 'Z') {
124 c1 += 0x20;
125 }
126 if (c0 != c1) {
127 return false;
128 }
129 }
130 return true;
131 }
133 public static boolean literalEqualsString(@Literal String literal, String string) {
134 return literal.equals(string);
135 }
137 public static boolean stringEqualsString(String one, String other) {
138 return one.equals(other);
139 }
141 public static void delete(Object o) {
143 }
145 public static void deleteArray(Object o) {
147 }
148 }