- Author
- Laurent NAVARRO ln@al.nosp@m.tide.nosp@m.v.com
- Version
- 0.4 2014-09-03
- Copyright
- MIT X11 : See .h file header Copyright (C) 2013 Laurent NAVARRO Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL LAURENT NAVARRO BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of the Laurent NAVARRO shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from the Laurent NAVARRO.
Description
AString is a library providing a C++ Ansi (8 bits char set) String class
I've create it because, I work with several compiler and it's often difficult to decide which string class I should use, because some compiler have their own framework string class (Visual Studio CString, QT QString,C++ Builder AnsiString) and all of them support std::string and C char*. I could always use std:string but framework's strings are generally a bit more richer in features. I'm also doing multi-threading but on pre-c++ 11 there's no guarantee std::string works fine, you have to investigate, sometimes it's ok, sometimes it's not OK.
AString provide the following features :
- an interface similar (not identical) to std::string
- Can be implemented with std:string or not (#define based). If not, it's a simple buffer based implementation (easy to debug)
- include interoperability with frameworks string class (C++ Builder,CString )
- include constructor from numbers (int, float, double, ... ) and also String To Number methods (ToInt, ... )
- include sprintf/format like feature
- include a secured strncpy char* copier
- include implode and explode (split/merge of string array)
- Buffer based implementation can be directly used on printf with s on some compiler
- Can easily be modified
Documentation
Documentation is generated using Doxygen, available online here http://www.altidev.com/ln/AString/ or at chm format here AString.chm and on the repository.
Configuration details
Some configuration can be done by settings some define on the — Write your settings Here — section of the Header file
Here a summary See source for details :
- ASTRING_IMPLEMENT_WITH_STD_STRING make AString inherits from std::string (probably better if you fully trust it) instead of the buffer based implementation
- ASTRING_INTEROP_STD_STRING for buffer base implementation, allow transparent interoperability with std::string (constructor & cast operator)
- ASTRING_NOSTL remove all feature using STL like vector et stream.
- ASTRING_INTEROP_BCB Enable interoperability with C++ Builder AnsiString and UnicodeString (constructor & cast operator)
- ASTRING_INTEROP_VSS Enable interoperability with Visual Studio CString (constructor & cast operator)
Implementation details
if ASTRING_IMPLEMENT_WITH_STD_STRING
is set to 0 the string is implemented by a pointer on a buffer.
However a specific tips was used to allow string to be used on s printf like function on some compiler inspired from Chris OldWood blog A Not-So-Clever-Now String Implementation
The tips consists to have a pointer pointing on the full buffer itself but on the char* section of the buffer and to compute with offset to access to stored size and capacity attributes as described here.
+--------------+
+ Size + <-- StrBuffer - 2*sizeof(unsigned) or GetSize() or GetRawBuffer()
+--------------+
+ Capacity + <-- StrBuffer - 1*sizeof(unsigned) or GetCapacity()
+--------------+
+ char* Buffer + <-- StrBuffer Attribute, conatains zero terminated characters string.
+--------------+
- Todo:
- Add missing std::string reimplementation (rfind)
- Add some features ToUpper, ToLower
- Add some useful string simple algorithms
- ToIntFromHex "0x20" or "20" to 32 , ToIntFromBin "0101" to 5
- assignAsHex 32 to "0x20" or "20" optional 0x
- assignAsBin 5 to "0101" parameter to set width and space on result (0101 0011 if param=4)
- Finalize/improve documentation and tests, test on Clang
- Add interaction with some others frameworks (QT, WxWidget, ... )
- Improve implementation of CString interoperability (make constructor param const by avoiding get buffer
Test details
I'm using the TDD logic for this library, so it include mainly project to run CPP Unit Project include test project on
- CodeBlock with Mingw GCC in Windows 32 bits
- CodeBlock with GCC on Linux Fedora 17 32bits
- CodeBlock with GCC on Linux Debian 7 64bits
- Visual Sutdio 2010 32 & 64 bits
- C++ Builder XE2 32 bits
I've done memory check using visual leak detector on Visual Studio http://vld.codeplex.com/
And DrMemory on Windows
And valgring on Linux, here command to test :
- valgrind –tool=memcheck bin/Debug/AStringUT
- valgrind –leak-check=full –tool=memcheck bin/Debug/AStringUT 've done coverage test on GCC using GCov 've used CppCheck also.
Release History
- version 0.1 2013-08-22 Initial
- version 0.2 2013-12-29
- Adding Replace of string by a string
- Adding trim, ltrim, rtrim
- version 0.3 2014-05-02
- Bugfix on comparison operator
- Added Char* on left of comparison operator
- version 0.4 2014-09-03
- Added test for 100% coverage on Gcc
- Minor Bugfix in case of reserve(0)