character_string.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. #ifndef CHARACTER_STRING_H
  15. #define CHARACTER_STRING_H
  16. #include <string>
  17. #include <exceptions/exceptions.h>
  18. #include <util/buffer.h>
  19. namespace isc {
  20. namespace dns {
  21. // \brief Some utility functions to extract <character-string> from string
  22. // or InputBuffer
  23. //
  24. // <character-string> is expressed in one or two ways: as a contiguous set
  25. // of characters without interior spaces, or as a string beginning with a "
  26. // and ending with a ". Inside a " delimited string any character can
  27. // occur, except for a " itself, which must be quoted using \ (back slash).
  28. // Ref. RFC1035
  29. namespace characterstr {
  30. /// Get a <character-string> from a string
  31. ///
  32. /// \param input_str The input string
  33. /// \param input_iterator The iterator from which to start extracting,
  34. /// the iterator will be updated to new position after the function
  35. /// is returned
  36. /// \param quoted If not \c NULL, returns \c true at this address if
  37. /// the string is quoted, \cfalse otherwise
  38. /// \return A std::string that contains the extracted <character-string>
  39. std::string getNextCharacterString(const std::string& input_str,
  40. std::string::const_iterator& input_iterator,
  41. bool* quoted = NULL);
  42. /// Get a <character-string> from a input buffer
  43. ///
  44. /// \param buffer The input buffer
  45. /// \param len The input buffer total length
  46. /// \return A std::string that contains the extracted <character-string>
  47. std::string getNextCharacterString(util::InputBuffer& buffer, size_t len);
  48. } // namespace characterstr
  49. } // namespace dns
  50. } // namespace isc
  51. #endif // CHARACTER_STRING_H