| Class | Line # | Actions | |||
|---|---|---|---|---|---|
| HTTPTokener | 34 | 20 | 9 |
| 1 | package org.json; | |
| 2 | ||
| 3 | /* | |
| 4 | Copyright (c) 2002 JSON.org | |
| 5 | ||
| 6 | Permission is hereby granted, free of charge, to any person obtaining a copy | |
| 7 | of this software and associated documentation files (the "Software"), to deal | |
| 8 | in the Software without restriction, including without limitation the rights | |
| 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
| 10 | copies of the Software, and to permit persons to whom the Software is | |
| 11 | furnished to do so, subject to the following conditions: | |
| 12 | ||
| 13 | The above copyright notice and this permission notice shall be included in all | |
| 14 | copies or substantial portions of the Software. | |
| 15 | ||
| 16 | The Software shall be used for Good, not Evil. | |
| 17 | ||
| 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
| 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
| 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
| 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
| 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
| 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
| 24 | SOFTWARE. | |
| 25 | */ | |
| 26 | ||
| 27 | /** | |
| 28 | * The HTTPTokener extends the JSONTokener to provide additional methods for the | |
| 29 | * parsing of HTTP headers. | |
| 30 | * | |
| 31 | * @author JSON.org | |
| 32 | * @version 2015-12-09 | |
| 33 | */ | |
| 34 | public class HTTPTokener extends JSONTokener | |
| 35 | { | |
| 36 | ||
| 37 | /** | |
| 38 | * Construct an HTTPTokener from a string. | |
| 39 | * | |
| 40 | * @param string | |
| 41 | * A source string. | |
| 42 | */ | |
| 43 | 0 | public HTTPTokener(String string) |
| 44 | { | |
| 45 | 0 | super(string); |
| 46 | } | |
| 47 | ||
| 48 | /** | |
| 49 | * Get the next token or string. This is used in parsing HTTP headers. | |
| 50 | * | |
| 51 | * @throws JSONException | |
| 52 | * @return A String. | |
| 53 | */ | |
| 54 | 0 | public String nextToken() throws JSONException |
| 55 | { | |
| 56 | 0 | char c; |
| 57 | 0 | char q; |
| 58 | 0 | StringBuilder sb = new StringBuilder(); |
| 59 | 0 | do |
| 60 | { | |
| 61 | 0 | c = next(); |
| 62 | 0 | } while (Character.isWhitespace(c)); |
| 63 | 0 | if (c == '"' || c == '\'') |
| 64 | { | |
| 65 | 0 | q = c; |
| 66 | 0 | for (;;) |
| 67 | { | |
| 68 | 0 | c = next(); |
| 69 | 0 | if (c < ' ') |
| 70 | { | |
| 71 | 0 | throw syntaxError("Unterminated string."); |
| 72 | } | |
| 73 | 0 | if (c == q) |
| 74 | { | |
| 75 | 0 | return sb.toString(); |
| 76 | } | |
| 77 | 0 | sb.append(c); |
| 78 | } | |
| 79 | } | |
| 80 | 0 | for (;;) |
| 81 | { | |
| 82 | 0 | if (c == 0 || Character.isWhitespace(c)) |
| 83 | { | |
| 84 | 0 | return sb.toString(); |
| 85 | } | |
| 86 | 0 | sb.append(c); |
| 87 | 0 | c = next(); |
| 88 | } | |
| 89 | } | |
| 90 | } |