Java IRC bot
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

HTTPTokener.java 2.3KB

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