11package org .wordpress .android .util ;
22
3+ import android .content .Context ;
4+ import android .support .annotation .StringRes ;
35import android .text .Html ;
46import android .text .TextUtils ;
57
@@ -63,7 +65,7 @@ public static String addPTags(String source) {
6365 String trimmed = asploded [i ].trim ();
6466 if (trimmed .length () > 0 ) {
6567 trimmed = trimmed .replace ("<br />" , "<br>" ).replace ("<br/>" , "<br>" ).replace ("<br>\n " , "<br>" )
66- .replace ("\n " , "<br>" );
68+ .replace ("\n " , "<br>" );
6769 wrappedHTML .append ("<p>" );
6870 wrappedHTML .append (trimmed );
6971 wrappedHTML .append ("</p>" );
@@ -186,7 +188,7 @@ public static String removeTrailingSlash(final String str) {
186188 return str ;
187189 }
188190
189- return str .substring (0 , str .length () -1 );
191+ return str .substring (0 , str .length () - 1 );
190192 }
191193
192194 /*
@@ -223,14 +225,13 @@ public static String replaceUnicodeSurrogateBlocksWithHTMLEntities(final String
223225 * Used to convert a language code ([lc]_[rc] where lc is language code (en, fr, es, etc...)
224226 * and rc is region code (zh-CN, zh-HK, zh-TW, etc...) to a displayable string with the languages
225227 * name.
226- *
228+ * <p/>
227229 * The input string must be between 2 and 6 characters, inclusive. An empty string is returned
228230 * if that is not the case.
229- *
231+ * <p/>
230232 * If the input string is recognized by {@link Locale} the result of this method is the given
231233 *
232- * @return
233- * non-null
234+ * @return non-null
234235 */
235236 public static String getLanguageString (String languagueCode , Locale displayLocale ) {
236237 if (languagueCode == null || languagueCode .length () < 2 || languagueCode .length () > 6 ) {
@@ -262,11 +263,11 @@ public static final String stripNonValidXMLCharacters(String in) {
262263 for (int i = 0 ; i < in .length (); i ++) {
263264 current = in .charAt (i ); // NOTE: No IndexOutOfBoundsException caught here; it should not happen.
264265 if ((current == 0x9 ) ||
265- (current == 0xA ) ||
266- (current == 0xD ) ||
267- ((current >= 0x20 ) && (current <= 0xD7FF )) ||
268- ((current >= 0xE000 ) && (current <= 0xFFFD )) ||
269- ((current >= 0x10000 ) && (current <= 0x10FFFF ))) {
266+ (current == 0xA ) ||
267+ (current == 0xD ) ||
268+ ((current >= 0x20 ) && (current <= 0xD7FF )) ||
269+ ((current >= 0xE000 ) && (current <= 0xFFFD )) ||
270+ ((current >= 0x10000 ) && (current <= 0x10FFFF ))) {
270271 out .append (current );
271272 }
272273 }
@@ -279,6 +280,7 @@ public static final String stripNonValidXMLCharacters(String in) {
279280 public static int stringToInt (String s ) {
280281 return stringToInt (s , 0 );
281282 }
283+
282284 public static int stringToInt (String s , int defaultValue ) {
283285 if (s == null )
284286 return defaultValue ;
@@ -292,6 +294,7 @@ public static int stringToInt(String s, int defaultValue) {
292294 public static long stringToLong (String s ) {
293295 return stringToLong (s , 0L );
294296 }
297+
295298 public static long stringToLong (String s , long defaultValue ) {
296299 if (s == null )
297300 return defaultValue ;
@@ -301,4 +304,18 @@ public static long stringToLong(String s, long defaultValue) {
301304 return defaultValue ;
302305 }
303306 }
307+
308+ /**
309+ * We need this because our translation platform doesn't support plurals.
310+ */
311+ public static String getQuantityString (Context context , @ StringRes int zero , @ StringRes int one ,
312+ @ StringRes int other , int count ) {
313+ if (count == 0 ) {
314+ return context .getString (zero );
315+ }
316+ if (count == 1 ) {
317+ return context .getString (one );
318+ }
319+ return context .getString (other , count );
320+ }
304321}
0 commit comments