/soc/2012/michael/android: b56bb8432f76: Fixed enum parser which...

Michael Zangl michael at soc.pidgin.im
Sat Jul 7 03:34:25 EDT 2012


Changeset: b56bb8432f765cebe4cb67194c633918aff0aebb
Author:	 Michael Zangl <michael at soc.pidgin.im>
Date:	 2012-06-30 16:49 +0200
Branch:	 soc.2012.android
URL: http://hg.pidgin.im/soc/2012/michael/android/rev/b56bb8432f76

Description:

Fixed enum parser which could not handle shifts in enum Values, e.g. 1<<2.

diffstat:

 android/workspace/im.pidgin.libpurple.build/src/im/pidgin/libpurple/build/constants/ConstantExtractor.java |  13 +++++++--
 android/workspace/im.pidgin.libpurple.build/src/im/pidgin/libpurple/build/constants/EnumObject.java        |   3 +-
 2 files changed, 12 insertions(+), 4 deletions(-)

diffs (49 lines):

diff --git a/android/workspace/im.pidgin.libpurple.build/src/im/pidgin/libpurple/build/constants/ConstantExtractor.java b/android/workspace/im.pidgin.libpurple.build/src/im/pidgin/libpurple/build/constants/ConstantExtractor.java
--- a/android/workspace/im.pidgin.libpurple.build/src/im/pidgin/libpurple/build/constants/ConstantExtractor.java
+++ b/android/workspace/im.pidgin.libpurple.build/src/im/pidgin/libpurple/build/constants/ConstantExtractor.java
@@ -15,6 +15,8 @@
  * 
  */
 public class ConstantExtractor {
+	private static final Pattern SHIFT_PATTERN = Pattern
+			.compile("(\\d+)\\s*<<\\s*(\\d+)");
 	private static final String DEFINE_LINE = "#define\\s+(\\w+)[ \\t]+([^\\n]*)";
 	private static final Pattern ENUM_OR_DEFINE = Pattern.compile("("
 			+ DEFINE_LINE + ")|(" + EnumObject.ENUM_PATTERN_STRING + ")");
@@ -66,15 +68,20 @@
 			foundIntConstants.put(name, intValue);
 		} catch (NumberFormatException e) {
 			// just silently ignore it.
-			//String stringValue = getStringValue(value);
-			//foundStringConstants.put(name, stringValue);
+			// String stringValue = getStringValue(value);
+			// foundStringConstants.put(name, stringValue);
 		}
 
 	}
 
 	protected static int parseInteger(String value) {
 		int intValue;
-		if (value.startsWith("0x")) {
+		Matcher shiftMatcher = SHIFT_PATTERN.matcher(value);
+		if (shiftMatcher.matches()) {
+			int a = parseInteger(shiftMatcher.group(1));
+			int b = parseInteger(shiftMatcher.group(2));
+			intValue = a << b;
+		} else if (value.startsWith("0x")) {
 			intValue = Integer.parseInt(value.substring(2), 16);
 		} else if (value.startsWith("0")) {
 			intValue = Integer.parseInt(value, 8);
diff --git a/android/workspace/im.pidgin.libpurple.build/src/im/pidgin/libpurple/build/constants/EnumObject.java b/android/workspace/im.pidgin.libpurple.build/src/im/pidgin/libpurple/build/constants/EnumObject.java
--- a/android/workspace/im.pidgin.libpurple.build/src/im/pidgin/libpurple/build/constants/EnumObject.java
+++ b/android/workspace/im.pidgin.libpurple.build/src/im/pidgin/libpurple/build/constants/EnumObject.java
@@ -10,7 +10,8 @@
  * 
  */
 public class EnumObject {
-	private static final String ITEM_PATTERN_STRING = "\\s*(\\w+)\\s*(?:=\\s*(-?\\d+|0x[\\da-fA-F]+)\\s*)?";
+	private static final String NUMBER_PATTERN = "(?:-?\\d+|0x[\\da-fA-F]+|\\d+\\s*<<\\s*\\d+)";
+	private static final String ITEM_PATTERN_STRING = "\\s*(\\w+)\\s*(?:=\\s*(" + NUMBER_PATTERN + ")\\s*)?";
 	private static final Pattern ITEM_PATTERN = Pattern
 			.compile(ITEM_PATTERN_STRING);
 	private static final String IGNORED_ENUM_PARTS = "/\\*[\\s\\S]*?\\*/|//[^\\n]*";



More information about the Commits mailing list