From 130f864d1d3f02f854a5f4085a49318a03a8eea0 Mon Sep 17 00:00:00 2001 From: Albrecht Schlosser Date: Sat, 4 Dec 2021 15:50:10 +0100 Subject: Rename src/Fl_String.cxx to src/Fl_String_class.cxx Sorry for the noise, still fixing a name class on case-insensitive file systems (macOS and Windows). --- src/CMakeLists.txt | 2 +- src/Fl_String.cxx | 159 ------------------------------------------------ src/Fl_String_class.cxx | 159 ++++++++++++++++++++++++++++++++++++++++++++++++ src/Makefile | 2 +- src/makedepend | 2 +- 5 files changed, 162 insertions(+), 162 deletions(-) delete mode 100644 src/Fl_String.cxx create mode 100644 src/Fl_String_class.cxx (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 19168612e..475712ccf 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -79,7 +79,7 @@ set (CPPFILES Fl_Single_Window.cxx Fl_Slider.cxx Fl_Spinner.cxx - Fl_String.cxx + Fl_String_class.cxx Fl_Sys_Menu_Bar.cxx Fl_System_Driver.cxx Fl_Table.cxx diff --git a/src/Fl_String.cxx b/src/Fl_String.cxx deleted file mode 100644 index f0aa4f405..000000000 --- a/src/Fl_String.cxx +++ /dev/null @@ -1,159 +0,0 @@ -// -// Basic Fl_String class for the Fast Light Tool Kit (FLTK). -// -// Copyright 2021 by Bill Spitzak and others. -// -// This library is free software. Distribution and use rights are outlined in -// the file "COPYING" which should have been included with this file. If this -// file is missing or damaged, see the license at: -// -// https://www.fltk.org/COPYING.php -// -// Please see the following page on how to report bugs and issues: -// -// https://www.fltk.org/bugs.php -// - -#include - -#include -#include - -/** \file src/Fl_String.cxx - Basic Fl_String class for FLTK. -*/ - -static int string_count; - -Fl_String::Fl_String() { - string_count++; - init(); - // debug("created ()"); -} - -Fl_String::Fl_String(const char *str) { - string_count++; - init(); - value(str); - // debug("created (str)"); -} - -Fl_String::Fl_String(const char *str, int size) { - string_count++; - init(); - value(str, size); - // debug("created (str, size)"); -} - -void Fl_String::init() { - size_ = 0; - value_ = 0; - capacity_ = 0; -} - -// copy constructor -Fl_String::Fl_String(const Fl_String &in) { - string_count++; - init(); - value(in.value(), in.size()); - // debug("copied (c'tor)"); -} - -// copy assignment operator -Fl_String& Fl_String::operator=(const Fl_String &in) { - if (this == &in) - return *this; - value(in.value(), in.size()); - // debug("copy assigned"); - return *this; -} - -// assignment operator for 'const char *' -Fl_String& Fl_String::operator=(const char *in) { - value(in); - // debug("*STRING* assigned"); - return *this; -} - -Fl_String::~Fl_String() { - string_count--; - // debug("~Fl_String()"); - delete[] value_; -} - -void Fl_String::alloc_buf(int size) { - if (size < 0) - return; - if (size > 0 && size <= capacity_) - return; - if (capacity_ > 0) - return; - - int new_size = (size + 1 + 15) & (~15); // round upwards - char *new_value = new char[new_size]; - capacity_ = new_size - 1; - - size_ = 0; - delete[] value_; - value_ = new_value; -} - -void Fl_String::value(const char *str) { - value(str, str ? strlen(str) : 0); -} - -int Fl_String::slen() const { - if (!value_) return 0; - return (int)strlen(value_); -} - -void Fl_String::value(const char *str, int len) { - if (str) { - alloc_buf(len); - size_ = len; - memcpy(value_, str, size_); - value_[size_] = '\0'; - } else { // str == NULL - size_ = 0; // ignore len ! - delete[] value_; // free buffer - value_ = NULL; // set null pointer (!) - capacity_ = 0; // reset capacity - } -} - -int Fl_String::capacity() const { - return capacity_; // > 0 ? capacity_ - 1 : capacity_; -} - -void Fl_String::release() { - delete[] value_; - value_ = 0; - size_ = 0; - capacity_ = 0; -} - -// ============================= DEBUG ============================= - -static const char fl_string_debug = 0; - -void Fl_String::debug(const char *info) const { - if (fl_string_debug) { - printf("Fl_String[%2d] '%-20s': %p, value = %p (%d/%d): '%s'.\n", - string_count, info, this, value_, size_, capacity_, value_); - } -} - -void Fl_String::hexdump(const char *info) const { - if (fl_string_debug) { - debug(info); - for (int i = 0; i < size_; i++) { - if ((i & 15) == 0) { - if (i > 0) printf("\n"); - printf(" [%04x %4d] ", i, i); - } else if ((i & 3) == 0) - printf(" "); - printf(" %02x", (unsigned char)value_[i]); - } - printf("\n"); - } -} diff --git a/src/Fl_String_class.cxx b/src/Fl_String_class.cxx new file mode 100644 index 000000000..f0aa4f405 --- /dev/null +++ b/src/Fl_String_class.cxx @@ -0,0 +1,159 @@ +// +// Basic Fl_String class for the Fast Light Tool Kit (FLTK). +// +// Copyright 2021 by Bill Spitzak and others. +// +// This library is free software. Distribution and use rights are outlined in +// the file "COPYING" which should have been included with this file. If this +// file is missing or damaged, see the license at: +// +// https://www.fltk.org/COPYING.php +// +// Please see the following page on how to report bugs and issues: +// +// https://www.fltk.org/bugs.php +// + +#include + +#include +#include + +/** \file src/Fl_String.cxx + Basic Fl_String class for FLTK. +*/ + +static int string_count; + +Fl_String::Fl_String() { + string_count++; + init(); + // debug("created ()"); +} + +Fl_String::Fl_String(const char *str) { + string_count++; + init(); + value(str); + // debug("created (str)"); +} + +Fl_String::Fl_String(const char *str, int size) { + string_count++; + init(); + value(str, size); + // debug("created (str, size)"); +} + +void Fl_String::init() { + size_ = 0; + value_ = 0; + capacity_ = 0; +} + +// copy constructor +Fl_String::Fl_String(const Fl_String &in) { + string_count++; + init(); + value(in.value(), in.size()); + // debug("copied (c'tor)"); +} + +// copy assignment operator +Fl_String& Fl_String::operator=(const Fl_String &in) { + if (this == &in) + return *this; + value(in.value(), in.size()); + // debug("copy assigned"); + return *this; +} + +// assignment operator for 'const char *' +Fl_String& Fl_String::operator=(const char *in) { + value(in); + // debug("*STRING* assigned"); + return *this; +} + +Fl_String::~Fl_String() { + string_count--; + // debug("~Fl_String()"); + delete[] value_; +} + +void Fl_String::alloc_buf(int size) { + if (size < 0) + return; + if (size > 0 && size <= capacity_) + return; + if (capacity_ > 0) + return; + + int new_size = (size + 1 + 15) & (~15); // round upwards + char *new_value = new char[new_size]; + capacity_ = new_size - 1; + + size_ = 0; + delete[] value_; + value_ = new_value; +} + +void Fl_String::value(const char *str) { + value(str, str ? strlen(str) : 0); +} + +int Fl_String::slen() const { + if (!value_) return 0; + return (int)strlen(value_); +} + +void Fl_String::value(const char *str, int len) { + if (str) { + alloc_buf(len); + size_ = len; + memcpy(value_, str, size_); + value_[size_] = '\0'; + } else { // str == NULL + size_ = 0; // ignore len ! + delete[] value_; // free buffer + value_ = NULL; // set null pointer (!) + capacity_ = 0; // reset capacity + } +} + +int Fl_String::capacity() const { + return capacity_; // > 0 ? capacity_ - 1 : capacity_; +} + +void Fl_String::release() { + delete[] value_; + value_ = 0; + size_ = 0; + capacity_ = 0; +} + +// ============================= DEBUG ============================= + +static const char fl_string_debug = 0; + +void Fl_String::debug(const char *info) const { + if (fl_string_debug) { + printf("Fl_String[%2d] '%-20s': %p, value = %p (%d/%d): '%s'.\n", + string_count, info, this, value_, size_, capacity_, value_); + } +} + +void Fl_String::hexdump(const char *info) const { + if (fl_string_debug) { + debug(info); + for (int i = 0; i < size_; i++) { + if ((i & 15) == 0) { + if (i > 0) printf("\n"); + printf(" [%04x %4d] ", i, i); + } else if ((i & 3) == 0) + printf(" "); + printf(" %02x", (unsigned char)value_[i]); + } + printf("\n"); + } +} diff --git a/src/Makefile b/src/Makefile index 2fe252ba8..1b854ad57 100644 --- a/src/Makefile +++ b/src/Makefile @@ -81,7 +81,7 @@ CPPFILES = \ Fl_Single_Window.cxx \ Fl_Slider.cxx \ Fl_Spinner.cxx \ - Fl_String.cxx \ + Fl_String_class.cxx \ Fl_Sys_Menu_Bar.cxx \ Fl_System_Driver.cxx \ Fl_Table.cxx \ diff --git a/src/makedepend b/src/makedepend index 5f11d0d56..2bcdbb7ab 100644 --- a/src/makedepend +++ b/src/makedepend @@ -2968,11 +2968,11 @@ fl_string.o: ../FL/fl_casts.H fl_string.o: ../FL/Fl_Export.H fl_string.o: ../FL/Fl_Preferences.H fl_string.o: ../FL/fl_string.h -Fl_String.o: ../FL/Fl_String_class.H fl_string.o: ../FL/fl_types.h fl_string.o: ../FL/fl_utf8.h fl_string.o: ../FL/platform_types.h fl_string.o: Fl_System_Driver.H +Fl_String_class.o: ../FL/Fl_String_class.H Fl_SVG_Image.o: ../config.h Fl_SVG_Image.o: ../FL/abi-version.h Fl_SVG_Image.o: ../FL/Enumerations.H -- cgit v1.2.3