[ucsim] Update email and file info, fix stm8 flash controller
[sdcc.git] / sdcc / sim / ucsim / src / core / utils.src / charscl.h
blob44ed1323e9b7f54cea7fa77443ad6d894954d096
1 /*
2 * Simulator of microcontrollers (charscl.h)
4 * Copyright (C) 1997 Drotos Daniel
5 *
6 * To contact author send email to dr.dkdb@gmail.com
8 */
10 /* This file is part of microcontroller simulator: ucsim.
12 UCSIM is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
17 UCSIM is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with UCSIM; see the file COPYING. If not, write to the Free
24 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
25 02111-1307, USA. */
26 /*@1@*/
28 #ifndef CHARSCL_HEADER
29 #define CHARSCL_HEADER
32 class chars
34 protected:
35 char *chars_string; // stores the value
36 int chars_length; // track of string length
37 bool dynamic;
38 mutable int pars_pos;
39 public:
40 chars(void);
41 chars(char *s);
42 chars(const char *s);
43 chars(const chars &cs);
44 chars(const char *, const char *fmt, ...);
45 virtual ~chars(void);
46 private:
47 void allocate_string(const char *s);
48 void deallocate_string(void);
50 public:
51 const char *c_str(void) const { return chars_string; }
52 const char *cstr(void) const { return chars_string; }
53 char *str(void) { return chars_string; }
54 char c(int idx);
55 chars &append(const char *s);
56 chars &append(char c);
57 chars &appendf(const char *format, ...);
58 chars &appendn(const char *src, int n);
59 chars &format(const char *format, ...);
60 bool empty() const { return chars_length == 0; }
61 bool nempty() const { return !empty(); }
62 bool is_null()const { return !chars_string; }
63 chars &uppercase(void);
64 chars &subst(const char *what, char with);
65 chars &substr(int start, int maxlen);
66 int len() const { return chars_length; }
67 int length() const { return chars_length; }
68 void start_parse(void) const { start_parse(0); }
69 void start_parse(int at) const { pars_pos= at; }
70 chars token(const char *delims) const;
71 unsigned int htoi(void);
72 unsigned long long int htoll(void);
73 void ltrim(void);
74 void rtrim(void);
75 void trim() { ltrim(); rtrim(); }
76 void lrip(const char *cset);
77 void rrip(const char *cset);
78 void rrip(int nuof_chars);
79 void rip(const char *cset) { lrip(cset); rrip(cset); }
80 // search
81 bool starts_with(const char *x) const;
82 int first_pos(char c);
83 long int lint(void);
84 long int lint(int base);
85 public:
86 // Operators
88 // Cast
89 operator const char*(void) const { return(chars_string); };
90 // Assignment
91 chars &operator=(const char *s);
92 chars &operator=(const chars &cs);
93 // Arithmetic
94 chars operator+(char c) const;
95 chars operator+(const char *s) const;
96 chars &operator+=(char c) { return(append(c)); }
97 chars &operator+=(const char *s) { return(append(s)); }
98 // Boolean
99 bool equal(const char *) const;
100 bool operator==(const char *s) const;
101 bool operator!=(const char *s) const;
104 extern chars operator+(char s, const chars &cs);
107 #endif
109 /* End of utils.src/charscl.h */