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