javaunohelper/com/sun/star/lib/uno/helper/UnoUrl.java | 66 +++++++++--------- 1 file changed, 35 insertions(+), 31 deletions(-)
New commits: commit 608f330e22e25772eb888fa33d64f9b79c0ffcc8 Author: rbuj <robert....@gmail.com> Date: Sun Aug 10 19:34:40 2014 +0200 javaunohelper: Number parsing Change-Id: Ie6856ea4c196479aef1ce00a7cf2709fea8b3e42 Reviewed-on: https://gerrit.libreoffice.org/10860 Reviewed-by: David Tardon <dtar...@redhat.com> Tested-by: David Tardon <dtar...@redhat.com> diff --git a/javaunohelper/com/sun/star/lib/uno/helper/UnoUrl.java b/javaunohelper/com/sun/star/lib/uno/helper/UnoUrl.java index baeee60..0bae9d0 100644 --- a/javaunohelper/com/sun/star/lib/uno/helper/UnoUrl.java +++ b/javaunohelper/com/sun/star/lib/uno/helper/UnoUrl.java @@ -203,44 +203,48 @@ public class UnoUrl { return connection.getUninterpretedString(); } - private static int hexToInt(int ch) - throws com.sun.star.lang.IllegalArgumentException { - int c = Character.toLowerCase((char) ch); - boolean isDigit = ('0' <= c && c <= '9'); - boolean isValidChar = ('a' <= c && c <= 'f') || isDigit; - - if (!isValidChar) - throw new com.sun.star.lang.IllegalArgumentException( - "Invalid UTF-8 hex byte '" + c + "'."); - - return isDigit ? ch - '0' : 10 + ((char) c - 'a') & 0xF; - } - private static String decodeUTF8(String s) throws com.sun.star.lang.IllegalArgumentException { - ArrayList<Integer> v = new ArrayList<Integer>(); - for (int i = 0; i < s.length(); i++) { - int ch = s.charAt(i); + try { + if (s.contains("%")) { + ArrayList<Integer> v = new ArrayList<Integer>(); + int length = s.length(); + for (int i = 0; i < length; i++) { + int ch = s.charAt(i); + + if (ch == '%') { + if (i+3 > length) + throw new com.sun.star.lang.IllegalArgumentException( + "Incomplete trailing escape (%) pattern"); + try { + ch = Integer.parseInt(s.substring(i+1,i+3),16); + } catch (NumberFormatException e) { + throw new com.sun.star.lang.IllegalArgumentException(e.toString()); + } + if (ch < 0) + throw new com.sun.star.lang.IllegalArgumentException( + "Illegal hex characters in escape (%) pattern - negative value"); + i+=2; + } + + v.add(new Integer(ch)); + } - if (ch == '%') { - int hb = hexToInt(s.charAt(++i)); - int lb = hexToInt(s.charAt(++i)); - ch = (hb << 4) | lb; - } + int size = v.size(); + byte[] bytes = new byte[size]; + for (int i = 0; i < size; i++) { + Integer anInt = v.get(i); + bytes[i] = (byte) (anInt.intValue() & 0xFF); + } - v.add(new Integer(ch)); - } + return new String(bytes, "UTF-8"); - int size = v.size(); - byte[] bytes = new byte[size]; - for (int i = 0; i < size; i++) { - Integer anInt = v.get(i); - bytes[i] = (byte) (anInt.intValue() & 0xFF); - } + } else { - try { - return new String(bytes, "UTF-8"); + return new String(s.getBytes(), "UTF-8"); + + } } catch (UnsupportedEncodingException e) { throw new com.sun.star.lang.IllegalArgumentException( "Couldn't convert parameter string to UTF-8 string:" + e.getMessage()); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits