diff options
author | Ben Gruver <bgruv@google.com> | 2013-03-02 15:21:33 -0800 |
---|---|---|
committer | Ben Gruver <bgruv@google.com> | 2013-03-02 15:21:33 -0800 |
commit | 60d834f95104bcbe856f4100ec967f4aae67eb04 (patch) | |
tree | 39fb7235e4dc4fd5e7a43564e940ad65b228425e /util | |
parent | 6d607ebe1d7bccd4fdf220f0275207cb452501bd (diff) | |
download | smali-60d834f95104bcbe856f4100ec967f4aae67eb04.tar.gz |
Annotate StringDataItems
Diffstat (limited to 'util')
-rw-r--r-- | util/src/main/java/org/jf/util/Utf8Utils.java | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/util/src/main/java/org/jf/util/Utf8Utils.java b/util/src/main/java/org/jf/util/Utf8Utils.java index 1931bb0f..957e535d 100644 --- a/util/src/main/java/org/jf/util/Utf8Utils.java +++ b/util/src/main/java/org/jf/util/Utf8Utils.java @@ -24,12 +24,13 @@ package org.jf.util; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + /** * Constants of type <code>CONSTANT_Utf8_info</code>. */ public final class Utf8Utils { - - /** * Converts a string into its Java-style UTF-8 form. Java-style UTF-8 * differs from normal UTF-8 in the handling of character '\0' and @@ -174,7 +175,21 @@ public final class Utf8Utils { * @param utf16Length the number of utf16 characters in the string to decode * @return non-null; the converted string */ - public static String utf8BytesWithUtf16LengthToString(byte[] bytes, int start, int utf16Length) { + public static String utf8BytesWithUtf16LengthToString(@Nonnull byte[] bytes, int start, int utf16Length) { + return utf8BytesWithUtf16LengthToString(bytes, start, utf16Length, null); + } + + /** + * Converts an array of UTF-8 bytes into a string. + * + * @param bytes non-null; the bytes to convert + * @param start the start index of the utf8 string to convert + * @param utf16Length the number of utf16 characters in the string to decode + * @param readLength If non-null, the first element will contain the number of bytes read after the method exits + * @return non-null; the converted string + */ + public static String utf8BytesWithUtf16LengthToString(@Nonnull byte[] bytes, int start, int utf16Length, + @Nullable int[] readLength) { char[] chars = localBuffer.get(); if (chars == null || chars.length < utf16Length) { chars = new char[utf16Length]; @@ -182,7 +197,8 @@ public final class Utf8Utils { } int outAt = 0; - for (int at = start; utf16Length > 0; utf16Length--) { + int at = 0; + for (at = start; utf16Length > 0; utf16Length--) { int v0 = bytes[at] & 0xFF; char out; switch (v0 >> 4) { @@ -247,6 +263,10 @@ public final class Utf8Utils { outAt++; } + if (readLength != null && readLength.length > 0) { + readLength[0] = at - start; + readLength[0] = at - start; + } return new String(chars, 0, outAt); } |