FLTK 1.5.0
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
30#include <FL/Fl_Export.H>
31
32#include <string>
33
34#if 1
35
36// Since fltk 1.5.0, Fl_String is no longer needed and now maps to std::string.
37// Fl_String is not part of the public API. All occurrences of Fl_String in the
38// core library and in Fluid should be replaced with std::string. When done,
39// src/Fl_String.H and src/Fl_String.cxx can be deleted.
40using Fl_String = std::string;
41
42#else
43
44// See: https://en.cppreference.com/w/cpp/string/basic_string/basic_string
45
72class FL_EXPORT Fl_String {
73
74private:
75 /*
76 FLTK does no small string optimization.
77 If the string is empty and capacity is not set, buffer_ will be NULL.
78 */
79 char *buffer_;
80 int size_;
81 int capacity_;
82
83 void init_();
84 void grow_(int n);
85 void shrink_(int n);
86 Fl_String &replace_(int at, int n_del, const char *src, int n_ins);
87
88protected:
89 static const char NUL;
90
91public:
92 static const int npos;
93
94 // ---- Assignment
95 Fl_String();
96 Fl_String(const Fl_String &str);
97 Fl_String(const char *cstr);
98 Fl_String(const char *str, int size);
99 ~Fl_String();
100 Fl_String& operator=(const Fl_String &str);
101 Fl_String& operator=(const char *cstr);
102 Fl_String &assign(const Fl_String &str);
103 Fl_String &assign(const char *cstr);
104 Fl_String &assign(const char *str, int size);
105
106 // ---- Element Access
107 char at(int pos) const;
108 char operator[](int n) const;
109 char &operator[](int n);
110 const char *data() const;
111 char *data();
112 const char *c_str() const;
113
114 // ---- Capacity
115 bool empty() const;
116 int size() const;
117 void reserve(int n);
118 int capacity() const;
119 void shrink_to_fit();
120
121 // --- Operations
122 void clear();
123 Fl_String &insert(int at, const char *src, int n_ins=npos);
124 Fl_String &insert(int at, const Fl_String &src);
125 Fl_String &erase(int at, int n_del);
126 void push_back(char c);
127 void pop_back();
128 Fl_String &append(const char *src, int n_ins=npos);
129 Fl_String &append(const Fl_String &src);
130 Fl_String &append(char c);
131 Fl_String &operator+=(const char *src);
132 Fl_String &operator+=(const Fl_String &src);
133 Fl_String &operator+=(char c);
134 int find(const Fl_String &needle, int start_pos=0) const;
135 Fl_String &replace(int at, int n_del, const char *src, int n_ins=npos);
136 Fl_String &replace(int at, int n_del, const Fl_String &src);
137 Fl_String substr(int pos=0, int n=npos) const;
138 void resize(int n);
139
140 // --- Non Standard
141 int strlen() const;
142 void debug(const char *info = 0) const;
143 void hexdump(const char *info = 0) const;
144}; // class Fl_String
145
146// ---- Non-member functions
147FL_EXPORT Fl_String operator+(const Fl_String& lhs, const Fl_String& rhs);
148FL_EXPORT Fl_String operator+(const Fl_String& lhs, const char* rhs);
149FL_EXPORT bool operator==(const Fl_String & lhs, const Fl_String & rhs);
150FL_EXPORT bool operator!=(const Fl_String & lhs, const Fl_String & rhs);
151
152#endif
153
159#endif // _FL_Fl_String_H_