FLTK 1.4.5: Fl_String.H Source File

FLTK 1.4.5

Loading...
Searching...
No Matches
Fl_String.H
1//
2// Basic Fl_String header for the Fast Light Tool Kit (FLTK).
3//
4// Copyright 2021-2023 by Bill Spitzak and others.
5//
6// This library is free software. Distribution and use rights are outlined in
7// the file "COPYING" which should have been included with this file. If this
8// file is missing or damaged, see the license at:
9//
10// https://www.fltk.org/COPYING.php
11//
12// Please see the following page on how to report bugs and issues:
13//
14// https://www.fltk.org/bugs.php
15//
16
17#ifndef _FL_Fl_String_H_
18#define _FL_Fl_String_H_
19
25
29
30#include <FL/Fl_Export.H>
31
32// See: https://en.cppreference.com/w/cpp/string/basic_string/basic_string
33
60class FL_EXPORT Fl_String {
61
62private:
63 /*
64 FLTK does no small string optimization.
65 If the string is empty and capacity is not set, buffer_ will be NULL.
66 */
67 char *buffer_;
68 int size_;
69 int capacity_;
70
71 void init_();
72 void grow_(int n);
73 void shrink_(int n);
74 Fl_String &replace_(int at, int n_del, const char *src, int n_ins);
75
76protected:
77 static const char NUL;
78
79public:
80 static const int npos;
81
82 // ---- Assignment
83 Fl_String();
84 Fl_String(const Fl_String &str);
85 Fl_String(const char *cstr);
86 Fl_String(const char *str, int size);
87 ~Fl_String();
88 Fl_String& operator=(const Fl_String &str);
89 Fl_String& operator=(const char *cstr);
90 Fl_String &assign(const Fl_String &str);
91 Fl_String &assign(const char *cstr);
92 Fl_String &assign(const char *str, int size);
93
94 // ---- Element Access
95 char at(int pos) const;
96 char operator[](int n) const;
97 char &operator[](int n);
98 const char *data() const;
99 char *data();
100 const char *c_str() const;
101
102 // ---- Capacity
103 bool empty() const;
104 int size() const;
105 void reserve(int n);
106 int capacity() const;
107 void shrink_to_fit();
108
109 // --- Operations
110 void clear();
111 Fl_String &insert(int at, const char *src, int n_ins=npos);
112 Fl_String &insert(int at, const Fl_String &src);
113 Fl_String &erase(int at, int n_del);
114 void push_back(char c);
115 void pop_back();
116 Fl_String &append(const char *src, int n_ins=npos);
117 Fl_String &append(const Fl_String &src);
118 Fl_String &append(char c);
119 Fl_String &operator+=(const char *src);
120 Fl_String &operator+=(const Fl_String &src);
121 Fl_String &operator+=(char c);
122 int find(const Fl_String &needle, int start_pos=0) const;
123 Fl_String &replace(int at, int n_del, const char *src, int n_ins=npos);
124 Fl_String &replace(int at, int n_del, const Fl_String &src);
125 Fl_String substr(int pos=0, int n=npos) const;
126 void resize(int n);
127
128 // --- Non Standard
129 int strlen() const;
130 void debug(const char *info = 0) const;
131 void hexdump(const char *info = 0) const;
132}; // class Fl_String
133
134// ---- Non-member functions
135FL_EXPORT Fl_String operator+(const Fl_String& lhs, const Fl_String& rhs);
136FL_EXPORT Fl_String operator+(const Fl_String& lhs, const char* rhs);
137FL_EXPORT bool operator==(const Fl_String & lhs, const Fl_String & rhs);
138FL_EXPORT bool operator!=(const Fl_String & lhs, const Fl_String & rhs);
139
144
145#endif // _FL_Fl_String_H_