Sets a value for a key in the user info string.
(String s, String key, String value)
| 55 | * Sets a value for a key in the user info string. |
| 56 | */ |
| 57 | public static String Info_SetValueForKey(String s, String key, String value) { |
| 58 | |
| 59 | if (value == null || value.length() == 0) |
| 60 | return s; |
| 61 | |
| 62 | if (key.indexOf('\\') != -1 || value.indexOf('\\') != -1) { |
| 63 | Com.Printf("Can't use keys or values with a \\\n"); |
| 64 | return s; |
| 65 | } |
| 66 | |
| 67 | if (key.indexOf(';') != -1) { |
| 68 | Com.Printf("Can't use keys or values with a semicolon\n"); |
| 69 | return s; |
| 70 | } |
| 71 | |
| 72 | if (key.indexOf('"') != -1 || value.indexOf('"') != -1) { |
| 73 | Com.Printf("Can't use keys or values with a \"\n"); |
| 74 | return s; |
| 75 | } |
| 76 | |
| 77 | if (key.length() > Defines.MAX_INFO_KEY - 1 |
| 78 | || value.length() > Defines.MAX_INFO_KEY - 1) { |
| 79 | Com.Printf("Keys and values must be < 64 characters.\n"); |
| 80 | return s; |
| 81 | } |
| 82 | |
| 83 | StringBuffer sb = new StringBuffer(Info_RemoveKey(s, key)); |
| 84 | |
| 85 | if (sb.length() + 2 + key.length() + value.length() > Defines.MAX_INFO_STRING) { |
| 86 | |
| 87 | Com.Printf("Info string length exceeded\n"); |
| 88 | return s; |
| 89 | } |
| 90 | |
| 91 | sb.append('\\').append(key).append('\\').append(value); |
| 92 | |
| 93 | return sb.toString(); |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * Removes a key and value from an info string. |
no test coverage detected