cgv
Loading...
Searching...
No Matches
token.cxx
1#include "token.h"
2#include "scan.h"
3
4namespace cgv {
5 namespace utils {
6
8token::token() : begin(0), end(0)
9{
10}
12token::token(const char* _str) : begin(_str), end(_str)
13{
14 while (*end != 0)
15 ++end;
16}
17
19token::token(const char* _b, const char* _e) : begin(_b), end(_e)
20{
21}
23token::token(const std::string& s) : begin(&s[0]), end(&s[0]+s.length())
24{
25}
27//size_t token::get_length() const { return end-begin; }
29//size_t token::size() const { return end-begin; }
31//bool token::empty() const { return begin == end; }
33void token::skip(const std::string& skip_chars)
34{
35 while (begin < end && is_element(*begin, skip_chars)) ++begin;
36}
38void token::reverse_skip(const std::string& skip_chars)
39{
40 while (begin < end && is_element(*(end-1), skip_chars)) --end;
41}
42
44bool token::operator == (const char* s) const
45{
46 return to_string(*this) == s;
47}
49bool token::operator == (const std::string& s) const
50{
51 return to_string(*this) == s;
52}
54bool token::operator != (const char* s) const
55{
56 return to_string(*this) != s;
57}
59bool token::operator != (const std::string& s) const
60{
61 return to_string(*this) != s;
62}
63
64/*
66std::string token::str() const
67{
68 return empty()?std::string():std::string(begin, end-begin);
69}
70*/
72//char token::operator [] (unsigned int i) const { return begin[i]; }
73
74 }
75}
std::string to_string(const std::string &v, unsigned int w, unsigned int p, bool)
specialization of conversion from string to strings
bool is_element(char c, const std::string &s)
check if char c arises in string s
Definition scan.cxx:291
the cgv namespace
Definition print.h:11
Helper functions to process strings.
bool operator==(const char *s) const
compare to const char*
Definition token.cxx:44
void skip(const std::string &skip_chars)
set begin by skipping all instances of the given character set
Definition token.cxx:33
const char * begin
pointers that define the range of characters
Definition token.h:20
token()
construct with both pointers set to 0
Definition token.cxx:8
bool operator!=(const char *s) const
compare to const char*
Definition token.cxx:54
void reverse_skip(const std::string &skip_chars)
set end by skipping all instances of the given character set
Definition token.cxx:38