Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.distiller; | 5 package org.chromium.distiller; |
| 6 | 6 |
| 7 import com.google.gwt.regexp.shared.RegExp; | 7 import com.google.gwt.regexp.shared.RegExp; |
| 8 | 8 |
| 9 public class StringUtil { | 9 public class StringUtil { |
| 10 // For the whitespace-related functions below, Java's and Javascript's versi ons of '\s' and '\S' | 10 // For the whitespace-related functions below, Java's and Javascript's versi ons of '\s' and '\S' |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 35 } | 35 } |
| 36 | 36 |
| 37 public static boolean match(String input, String regex) { | 37 public static boolean match(String input, String regex) { |
| 38 return RegExp.compile(regex, "i").test(input); | 38 return RegExp.compile(regex, "i").test(input); |
| 39 } | 39 } |
| 40 | 40 |
| 41 public static String findAndReplace(String input, String regex, String repla ce) { | 41 public static String findAndReplace(String input, String regex, String repla ce) { |
| 42 return RegExp.compile(regex, "gi").replace(input, replace); | 42 return RegExp.compile(regex, "gi").replace(input, replace); |
| 43 } | 43 } |
| 44 | 44 |
| 45 public static native boolean containsWordCharacter(String s) /*-{ | 45 public static native boolean containsWordCharacter(String s) /*-{ |
|
cjhopman
2015/05/15 20:16:55
We need to ensure that
containsWordCharacter(s) =
wychen
2015/05/18 18:49:20
Deleted.
| |
| 46 return /[\w\u00C0-\u1FFF\u2C00-\uD7FF]/.test(s); | 46 return /[\w\u00C0-\u1FFF\u2C00-\uD7FF]/.test(s); |
| 47 }-*/; | 47 }-*/; |
| 48 | 48 |
| 49 public static native int countWords(String s) /*-{ | 49 public static native int countWords(String s) /*-{ |
|
cjhopman
2015/05/15 20:16:55
Does this new approach make sense everywhere that
cjhopman
2015/05/15 20:16:55
Maybe we should change the name of this to reflect
wychen
2015/05/18 18:49:20
Well, the goal of this function is still to count
wychen
2015/05/18 18:49:20
One problem I see is the title finding part. It co
| |
| 50 var m = s.match(/(\S*[\w\u00C0-\u1FFF\u2C00-\uD7FF]\S*)/g); | 50 // The following range includes broader alphabetical letters and Hangul Syllables. |
| 51 return m ? m.length : 0; | 51 var m = s.match(/(\S*[\w\u00C0-\u1FFF\uAC00-\uD7AF]\S*)/g); |
| 52 var c = (m ? m.length : 0); | |
| 53 // The following range includes Hiragana, Katakana, and CJK Unified Ideo graphs. | |
| 54 // Hangul Syllables are not included. | |
| 55 m = s.match(/([\u3040-\uA4CF])/g); | |
| 56 c += Math.ceil((m ? m.length : 0) * 0.55); | |
| 57 return c; | |
| 52 }-*/; | 58 }-*/; |
| 53 | 59 |
| 54 public static native String regexEscape(String s) /*-{ | 60 public static native String regexEscape(String s) /*-{ |
| 55 return s.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, "\\$&"); | 61 return s.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, "\\$&"); |
| 56 }-*/; | 62 }-*/; |
| 57 | 63 |
| 58 /* | 64 /* |
| 59 * Returns true if character is a digit. | 65 * Returns true if character is a digit. |
| 60 */ | 66 */ |
| 61 public static native boolean isDigit(Character c) /*-{ | 67 public static native boolean isDigit(Character c) /*-{ |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 79 /** | 85 /** |
| 80 * Returns the plain number if given string can be converted to one >= 0. | 86 * Returns the plain number if given string can be converted to one >= 0. |
| 81 * Returns -1 if string is empty or not all digits. | 87 * Returns -1 if string is empty or not all digits. |
| 82 */ | 88 */ |
| 83 public static int toNumber(String s) { | 89 public static int toNumber(String s) { |
| 84 if (s.isEmpty() || !StringUtil.isStringAllDigits(s)) return -1; | 90 if (s.isEmpty() || !StringUtil.isStringAllDigits(s)) return -1; |
| 85 return JavaScript.parseInt(s, 10); | 91 return JavaScript.parseInt(s, 10); |
| 86 } | 92 } |
| 87 | 93 |
| 88 } | 94 } |
| OLD | NEW |