(String options, String key, String defaultValue)
| 109 | } |
| 110 | |
| 111 | public static String getValue(String options, String key, String defaultValue) { |
| 112 | key = trimKey(key); |
| 113 | if (!options.endsWith(" ")) |
| 114 | options = options + " "; |
| 115 | key += '='; |
| 116 | int index=-1; |
| 117 | do { // Require that key not be preceded by a letter |
| 118 | index = options.indexOf(key, ++index); |
| 119 | if (index<0) return defaultValue; |
| 120 | } while (index!=0&&Character.isLetter(options.charAt(index-1))); |
| 121 | options = options.substring(index+key.length(), options.length()); |
| 122 | if (options.charAt(0)=='\'') { |
| 123 | index = options.indexOf("'",1); |
| 124 | if (index<0) |
| 125 | return defaultValue; |
| 126 | else |
| 127 | return options.substring(1, index); |
| 128 | } else if (options.charAt(0)=='[') { |
| 129 | int count = 1; |
| 130 | index = -1; |
| 131 | for (int i=1; i<options.length(); i++) { |
| 132 | char ch = options.charAt(i); |
| 133 | if (ch=='[') |
| 134 | count++; |
| 135 | else if (ch==']') |
| 136 | count--; |
| 137 | if (count==0) { |
| 138 | index = i; |
| 139 | break; |
| 140 | } |
| 141 | } |
| 142 | if (index<0) |
| 143 | return defaultValue; |
| 144 | else |
| 145 | return options.substring(1, index); |
| 146 | } else { |
| 147 | index = options.indexOf(" "); |
| 148 | if (index<0) |
| 149 | return defaultValue; |
| 150 | else |
| 151 | return options.substring(0, index); |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | public static String trimKey(String key) { |
| 156 | if (key==null) |
no test coverage detected