Advertisement
Guest User

Untitled

a guest
Apr 25th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. public static Bundle parse(String params) {
  2. String[] arrParams = params.split(",(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)");
  3. Bundle bundle = new Bundle(arrParams.length);
  4. for (String s : arrParams) {
  5. String[] arr = s.split("\\s*=\\s*");
  6. if (arr.length == 2) {
  7. final String str = arr[1];
  8. final String key = arr[0].replaceAll("\\s+", "");
  9. if (TextUtils.isDigitsOnly(str)) {
  10. bundle.putInt(key, Integer.parseInt(str));
  11. continue;
  12. }
  13. if (Boolean.TRUE.toString().equals(str)) {
  14. bundle.putBoolean(key, true);
  15. continue;
  16. }
  17.  
  18. if (Boolean.FALSE.toString().equals(str)) {
  19. bundle.putBoolean(key, false);
  20. continue;
  21. }
  22. bundle.putString(key, str);
  23. }
  24. }
  25. return bundle;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement