/indra/llcommon/llstreamtools.h

https://bitbucket.org/lindenlab/viewer-beta/ · C++ Header · 118 lines · 28 code · 26 blank · 64 comment · 0 complexity · ef1251a96f3082bf7f630c7107dab4ce MD5 · raw file

  1. /**
  2. * @file llstreamtools.h
  3. * @brief some helper functions for parsing legacy simstate and asset files.
  4. *
  5. * $LicenseInfo:firstyear=2005&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #ifndef LL_STREAM_TOOLS_H
  27. #define LL_STREAM_TOOLS_H
  28. #include <iostream>
  29. #include <string>
  30. // unless specifed otherwise these all return input_stream.good()
  31. // skips spaces and tabs
  32. LL_COMMON_API bool skip_whitespace(std::istream& input_stream);
  33. // skips whitespace and newlines
  34. LL_COMMON_API bool skip_emptyspace(std::istream& input_stream);
  35. // skips emptyspace and lines that start with a #
  36. LL_COMMON_API bool skip_comments_and_emptyspace(std::istream& input_stream);
  37. // skips to character after next newline
  38. LL_COMMON_API bool skip_line(std::istream& input_stream);
  39. // skips to beginning of next non-emptyspace
  40. LL_COMMON_API bool skip_to_next_word(std::istream& input_stream);
  41. // skips to character after the end of next keyword
  42. // a 'keyword' is defined as the first word on a line
  43. LL_COMMON_API bool skip_to_end_of_next_keyword(const char* keyword, std::istream& input_stream);
  44. // skip_to_start_of_next_keyword() is disabled -- might tickle corruption bug
  45. // in windows iostream
  46. // skips to beginning of next keyword
  47. // a 'keyword' is defined as the first word on a line
  48. //bool skip_to_start_of_next_keyword(const char* keyword, std::istream& input_stream);
  49. // characters are pulled out of input_stream and appended to output_string
  50. // returns result of input_stream.good() after characters are pulled
  51. LL_COMMON_API bool get_word(std::string& output_string, std::istream& input_stream);
  52. LL_COMMON_API bool get_line(std::string& output_string, std::istream& input_stream);
  53. // characters are pulled out of input_stream (up to a max of 'n')
  54. // and appended to output_string
  55. // returns result of input_stream.good() after characters are pulled
  56. LL_COMMON_API bool get_word(std::string& output_string, std::istream& input_stream, int n);
  57. LL_COMMON_API bool get_line(std::string& output_string, std::istream& input_stream, int n);
  58. // unget_line() is disabled -- might tickle corruption bug in windows iostream
  59. //// backs up the input_stream by line_size + 1 characters
  60. //bool unget_line(const std::string& line, std::istream& input_stream);
  61. // TODO -- move these string manipulator functions to a different file
  62. // removes the last char in 'line' if it matches 'c'
  63. // returns true if removed last char
  64. LL_COMMON_API bool remove_last_char(char c, std::string& line);
  65. // replaces escaped characters with the correct characters from left to right
  66. // "\\" ---> '\\'
  67. // "\n" ---> '\n'
  68. LL_COMMON_API void unescape_string(std::string& line);
  69. // replaces unescaped characters with expanded equivalents from left to right
  70. // '\\' ---> "\\"
  71. // '\n' ---> "\n"
  72. LL_COMMON_API void escape_string(std::string& line);
  73. // replaces each '\n' character with ' '
  74. LL_COMMON_API void replace_newlines_with_whitespace(std::string& line);
  75. // erases any double-quote characters in line
  76. LL_COMMON_API void remove_double_quotes(std::string& line);
  77. // the 'keyword' is defined as the first word on a line
  78. // the 'value' is everything after the keyword on the same line
  79. // starting at the first non-whitespace and ending right before the newline
  80. LL_COMMON_API void get_keyword_and_value(std::string& keyword,
  81. std::string& value,
  82. const std::string& line);
  83. // continue to read from the stream until you really can't
  84. // read anymore or until we hit the count. Some istream
  85. // implimentations have a max that they will read.
  86. // Returns the number of bytes read.
  87. LL_COMMON_API std::streamsize fullread(
  88. std::istream& istr,
  89. char* buf,
  90. std::streamsize requested);
  91. LL_COMMON_API std::istream& operator>>(std::istream& str, const char *tocheck);
  92. #endif