PageRenderTime 22ms CodeModel.GetById 13ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/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
 27#ifndef LL_STREAM_TOOLS_H
 28#define LL_STREAM_TOOLS_H
 29
 30#include <iostream>
 31#include <string>
 32
 33// unless specifed otherwise these all return input_stream.good()
 34
 35// skips spaces and tabs
 36LL_COMMON_API bool skip_whitespace(std::istream& input_stream);
 37
 38// skips whitespace and newlines
 39LL_COMMON_API bool skip_emptyspace(std::istream& input_stream);
 40
 41// skips emptyspace and lines that start with a #
 42LL_COMMON_API bool skip_comments_and_emptyspace(std::istream& input_stream);
 43
 44// skips to character after next newline
 45LL_COMMON_API bool skip_line(std::istream& input_stream);
 46
 47// skips to beginning of next non-emptyspace
 48LL_COMMON_API bool skip_to_next_word(std::istream& input_stream);
 49
 50// skips to character after the end of next keyword 
 51// a 'keyword' is defined as the first word on a line
 52LL_COMMON_API bool skip_to_end_of_next_keyword(const char* keyword, std::istream& input_stream);
 53
 54// skip_to_start_of_next_keyword() is disabled -- might tickle corruption bug 
 55// in windows iostream
 56// skips to beginning of next keyword
 57// a 'keyword' is defined as the first word on a line
 58//bool skip_to_start_of_next_keyword(const char* keyword, std::istream& input_stream);
 59
 60// characters are pulled out of input_stream and appended to output_string
 61// returns result of input_stream.good() after characters are pulled
 62LL_COMMON_API bool get_word(std::string& output_string, std::istream& input_stream);
 63LL_COMMON_API bool get_line(std::string& output_string, std::istream& input_stream);
 64
 65// characters are pulled out of input_stream (up to a max of 'n')
 66// and appended to output_string 
 67// returns result of input_stream.good() after characters are pulled
 68LL_COMMON_API bool get_word(std::string& output_string, std::istream& input_stream, int n);
 69LL_COMMON_API bool get_line(std::string& output_string, std::istream& input_stream, int n);
 70
 71// unget_line() is disabled -- might tickle corruption bug in windows iostream
 72//// backs up the input_stream by line_size + 1 characters
 73//bool unget_line(const std::string& line, std::istream& input_stream);
 74
 75// TODO -- move these string manipulator functions to a different file
 76
 77// removes the last char in 'line' if it matches 'c'
 78// returns true if removed last char
 79LL_COMMON_API bool remove_last_char(char c, std::string& line);
 80
 81// replaces escaped characters with the correct characters from left to right
 82// "\\" ---> '\\' 
 83// "\n" ---> '\n' 
 84LL_COMMON_API void unescape_string(std::string& line);
 85
 86// replaces unescaped characters with expanded equivalents from left to right
 87// '\\' ---> "\\" 
 88// '\n' ---> "\n" 
 89LL_COMMON_API void escape_string(std::string& line);
 90
 91// replaces each '\n' character with ' '
 92LL_COMMON_API void replace_newlines_with_whitespace(std::string& line);
 93
 94// erases any double-quote characters in line
 95LL_COMMON_API void remove_double_quotes(std::string& line);
 96
 97// the 'keyword' is defined as the first word on a line
 98// the 'value' is everything after the keyword on the same line
 99// starting at the first non-whitespace and ending right before the newline
100LL_COMMON_API void get_keyword_and_value(std::string& keyword, 
101						   std::string& value, 
102						   const std::string& line);
103
104// continue to read from the stream until you really can't
105// read anymore or until we hit the count.  Some istream
106// implimentations have a max that they will read.
107// Returns the number of bytes read.
108LL_COMMON_API std::streamsize fullread(
109	std::istream& istr,
110	char* buf,
111	std::streamsize requested);
112
113
114LL_COMMON_API std::istream& operator>>(std::istream& str, const char *tocheck);
115
116#endif
117
118