2001-12-24 03:51:06 +01:00
|
|
|
/*
|
2004-02-28 20:44:04 +01:00
|
|
|
* PROGRAM: string class definition
|
|
|
|
* MODULE: fb_string.h
|
|
|
|
* DESCRIPTION: Provides almost that same functionality,
|
2008-12-05 01:56:15 +01:00
|
|
|
* that STL::basic_string<char> does,
|
2004-02-28 20:44:04 +01:00
|
|
|
* but behaves MemoryPools friendly.
|
2001-12-24 03:51:06 +01:00
|
|
|
*
|
2004-02-28 20:44:04 +01:00
|
|
|
* The contents of this file are subject to the Initial
|
|
|
|
* Developer's Public License Version 1.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
|
|
|
* http://www.ibphoenix.com/main.nfs?a=ibphoenix&page=ibp_idpl.
|
2001-12-24 03:51:06 +01:00
|
|
|
*
|
2004-02-28 20:44:04 +01:00
|
|
|
* Software distributed under the License is distributed AS IS,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing rights
|
|
|
|
* and limitations under the License.
|
|
|
|
*
|
|
|
|
* The Original Code was created by Alexander Peshkoff
|
|
|
|
* for the Firebird Open Source RDBMS project.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2004 Alexander Peshkoff <peshkoff@mail.ru>
|
|
|
|
* and all contributors signed below.
|
|
|
|
*
|
|
|
|
* All Rights Reserved.
|
|
|
|
* Contributor(s): ______________________________________.
|
2001-12-24 03:51:06 +01:00
|
|
|
*/
|
|
|
|
|
2004-03-18 06:56:06 +01:00
|
|
|
#ifndef INCLUDE_FB_STRING_H
|
|
|
|
#define INCLUDE_FB_STRING_H
|
2004-02-08 18:08:34 +01:00
|
|
|
|
2004-04-29 00:36:29 +02:00
|
|
|
#include <stdio.h>
|
2004-02-08 18:08:34 +01:00
|
|
|
#include <string.h>
|
2006-01-10 16:01:03 +01:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
2007-08-20 15:22:49 +02:00
|
|
|
#include "firebird.h"
|
2001-12-24 03:51:06 +01:00
|
|
|
#include "../include/fb_types.h"
|
2004-02-08 18:08:34 +01:00
|
|
|
#include "../include/fb_exception.h"
|
2003-01-16 18:47:10 +01:00
|
|
|
#include "../common/classes/alloc.h"
|
2009-02-01 23:03:10 +01:00
|
|
|
#include "../common/classes/RefCounted.h"
|
2001-12-24 03:51:06 +01:00
|
|
|
|
|
|
|
namespace Firebird
|
|
|
|
{
|
2008-04-18 12:03:04 +02:00
|
|
|
class AbstractString : private AutoStorage
|
|
|
|
{
|
2004-02-08 18:08:34 +01:00
|
|
|
public:
|
|
|
|
typedef char char_type;
|
2004-06-30 01:31:12 +02:00
|
|
|
typedef size_t size_type;
|
|
|
|
typedef ptrdiff_t difference_type;
|
2004-02-08 18:08:34 +01:00
|
|
|
typedef char* pointer;
|
|
|
|
typedef const char* const_pointer;
|
|
|
|
typedef char& reference;
|
|
|
|
typedef const char& const_reference;
|
|
|
|
typedef char value_type;
|
|
|
|
typedef pointer iterator;
|
|
|
|
typedef const_pointer const_iterator;
|
|
|
|
static const size_type npos;
|
2004-06-27 00:23:19 +02:00
|
|
|
enum {INLINE_BUFFER_SIZE = 32, INIT_RESERVE = 16/*, KEEP_SIZE = 512*/};
|
2008-12-05 01:56:15 +01:00
|
|
|
|
2004-02-08 18:08:34 +01:00
|
|
|
protected:
|
2004-06-30 01:31:12 +02:00
|
|
|
typedef USHORT internal_size_type; // 16 bits!
|
2004-06-27 00:23:19 +02:00
|
|
|
char_type inlineBuffer[INLINE_BUFFER_SIZE];
|
|
|
|
char_type* stringBuffer;
|
2004-06-30 01:31:12 +02:00
|
|
|
internal_size_type stringLength, bufferSize;
|
2008-12-05 01:56:15 +01:00
|
|
|
|
2004-02-08 18:08:34 +01:00
|
|
|
private:
|
2008-04-18 12:03:04 +02:00
|
|
|
inline void checkPos(size_type pos) const
|
|
|
|
{
|
2004-02-08 18:08:34 +01:00
|
|
|
if (pos >= length()) {
|
|
|
|
fatal_exception::raise("Firebird::string - pos out of range");
|
|
|
|
}
|
|
|
|
}
|
2008-12-05 01:56:15 +01:00
|
|
|
|
2008-04-18 12:03:04 +02:00
|
|
|
static inline void checkLength(size_type len)
|
|
|
|
{
|
2004-06-27 00:23:19 +02:00
|
|
|
if (len > max_length()) {
|
|
|
|
fatal_exception::raise("Firebird::string - length exceeds predefined limit");
|
2004-02-08 18:08:34 +01:00
|
|
|
}
|
|
|
|
}
|
2004-05-26 18:10:56 +02:00
|
|
|
|
2004-06-30 01:31:12 +02:00
|
|
|
// Reserve buffer to allow storing at least newLen characters there
|
|
|
|
// (not including null terminator). Existing contents of our string are preserved.
|
2008-07-16 13:15:00 +02:00
|
|
|
void reserveBuffer(const size_type newLen)
|
2008-04-18 12:03:04 +02:00
|
|
|
{
|
2004-06-30 01:31:12 +02:00
|
|
|
size_type newSize = newLen + 1;
|
2009-02-03 12:02:00 +01:00
|
|
|
if (newSize > bufferSize)
|
|
|
|
{
|
2004-06-30 01:31:12 +02:00
|
|
|
// Make sure we do not exceed string length limit
|
|
|
|
checkLength(newLen);
|
|
|
|
|
2004-06-27 00:23:19 +02:00
|
|
|
// Order of assignments below is important in case of low memory conditions
|
|
|
|
|
|
|
|
// Grow buffer exponentially to prevent memory fragmentation
|
2004-07-09 07:22:46 +02:00
|
|
|
if (newSize / 2 < bufferSize)
|
2009-08-27 11:51:55 +02:00
|
|
|
newSize = size_t(bufferSize) * 2u;
|
2004-06-30 01:31:12 +02:00
|
|
|
|
|
|
|
// Do not grow buffer beyond string length limit
|
|
|
|
if (newSize > max_length() + 1)
|
|
|
|
newSize = max_length() + 1;
|
|
|
|
|
|
|
|
// Allocate new buffer
|
2004-06-27 00:23:19 +02:00
|
|
|
char_type *newBuffer = FB_NEW(getPool()) char_type[newSize];
|
2004-06-30 01:31:12 +02:00
|
|
|
|
2004-06-27 00:23:19 +02:00
|
|
|
// Carefully copy string data including null terminator
|
2009-06-03 15:13:08 +02:00
|
|
|
memcpy(newBuffer, stringBuffer, sizeof(char_type) * (stringLength + 1u));
|
2004-06-30 01:31:12 +02:00
|
|
|
|
|
|
|
// Deallocate old buffer if needed
|
|
|
|
if (stringBuffer != inlineBuffer)
|
|
|
|
delete[] stringBuffer;
|
|
|
|
|
2004-06-27 00:23:19 +02:00
|
|
|
stringBuffer = newBuffer;
|
2004-06-30 01:31:12 +02:00
|
|
|
bufferSize = static_cast<internal_size_type>(newSize);
|
2004-02-08 18:08:34 +01:00
|
|
|
}
|
2004-06-27 00:23:19 +02:00
|
|
|
}
|
2004-05-26 18:10:56 +02:00
|
|
|
|
2004-06-27 00:23:19 +02:00
|
|
|
// Make sure our buffer is large enough to store at least <length> characters in it
|
2008-12-05 01:56:15 +01:00
|
|
|
// (not including null terminator). Resulting buffer is not initialized.
|
2004-06-30 01:31:12 +02:00
|
|
|
// Use it in constructors only when stringBuffer is not assigned yet.
|
2008-07-16 13:15:00 +02:00
|
|
|
void initialize(const size_type len)
|
2008-04-18 12:03:04 +02:00
|
|
|
{
|
2004-06-30 01:31:12 +02:00
|
|
|
if (len < INLINE_BUFFER_SIZE) {
|
2004-06-27 00:23:19 +02:00
|
|
|
stringBuffer = inlineBuffer;
|
|
|
|
bufferSize = INLINE_BUFFER_SIZE;
|
2008-12-05 01:56:15 +01:00
|
|
|
}
|
|
|
|
else {
|
2004-06-29 14:41:22 +02:00
|
|
|
stringBuffer = NULL; // Be safe in case of exception
|
|
|
|
checkLength(len);
|
2004-06-30 01:31:12 +02:00
|
|
|
|
|
|
|
// Reserve a few extra bytes in the buffer
|
|
|
|
size_type newSize = len + 1 + INIT_RESERVE;
|
|
|
|
|
|
|
|
// Do not grow buffer beyond string length limit
|
|
|
|
if (newSize > max_length() + 1)
|
|
|
|
newSize = max_length() + 1;
|
|
|
|
|
|
|
|
// Allocate new buffer
|
2004-06-27 00:23:19 +02:00
|
|
|
stringBuffer = FB_NEW(getPool()) char_type[newSize];
|
2004-06-30 01:31:12 +02:00
|
|
|
bufferSize = static_cast<internal_size_type>(newSize);
|
2004-06-27 00:23:19 +02:00
|
|
|
}
|
2004-06-30 01:31:12 +02:00
|
|
|
stringLength = static_cast<internal_size_type>(len);
|
2004-06-27 00:23:19 +02:00
|
|
|
stringBuffer[stringLength] = 0;
|
2004-02-08 18:08:34 +01:00
|
|
|
}
|
2004-05-26 18:10:56 +02:00
|
|
|
|
2008-04-18 12:03:04 +02:00
|
|
|
void shrinkBuffer()
|
|
|
|
{
|
2004-06-27 00:23:19 +02:00
|
|
|
// Shrink buffer if we decide it is beneficial
|
2004-02-08 18:08:34 +01:00
|
|
|
}
|
2004-06-27 00:23:19 +02:00
|
|
|
|
2004-02-08 18:08:34 +01:00
|
|
|
protected:
|
2010-01-26 16:14:47 +01:00
|
|
|
AbstractString(const size_type sizeL, const void* datap);
|
2004-06-27 00:23:19 +02:00
|
|
|
|
2008-07-16 13:15:00 +02:00
|
|
|
AbstractString(const_pointer p1, const size_type n1,
|
|
|
|
const_pointer p2, const size_type n2);
|
2004-06-27 00:23:19 +02:00
|
|
|
|
2004-02-08 18:08:34 +01:00
|
|
|
AbstractString(const AbstractString& v);
|
2004-06-27 00:23:19 +02:00
|
|
|
|
2008-12-05 01:56:15 +01:00
|
|
|
inline AbstractString() :
|
2004-06-27 00:23:19 +02:00
|
|
|
stringBuffer(inlineBuffer), stringLength(0), bufferSize(INLINE_BUFFER_SIZE)
|
|
|
|
{
|
|
|
|
stringBuffer[0] = 0;
|
2004-02-08 18:08:34 +01:00
|
|
|
}
|
2004-06-27 00:23:19 +02:00
|
|
|
|
2008-07-16 13:15:00 +02:00
|
|
|
AbstractString(const size_type sizeL, char_type c);
|
2004-06-27 00:23:19 +02:00
|
|
|
|
|
|
|
inline explicit AbstractString(MemoryPool& p) : AutoStorage(p),
|
|
|
|
stringBuffer(inlineBuffer), stringLength(0), bufferSize(INLINE_BUFFER_SIZE)
|
|
|
|
{
|
|
|
|
stringBuffer[0] = 0;
|
2004-02-28 20:44:04 +01:00
|
|
|
}
|
2004-06-27 00:23:19 +02:00
|
|
|
|
2008-12-05 01:56:15 +01:00
|
|
|
inline AbstractString(MemoryPool& p, const AbstractString& v)
|
2004-03-14 14:22:16 +01:00
|
|
|
: AutoStorage(p)
|
2004-03-07 08:58:55 +01:00
|
|
|
{
|
2004-06-27 00:23:19 +02:00
|
|
|
initialize(v.length());
|
|
|
|
memcpy(stringBuffer, v.c_str(), stringLength);
|
2004-02-28 20:44:04 +01:00
|
|
|
}
|
2004-06-27 00:23:19 +02:00
|
|
|
|
2010-01-26 16:14:47 +01:00
|
|
|
inline AbstractString(MemoryPool& p, const void* s, const size_type l)
|
2004-03-31 20:07:34 +02:00
|
|
|
: AutoStorage(p)
|
|
|
|
{
|
2004-06-27 00:23:19 +02:00
|
|
|
initialize(l);
|
|
|
|
memcpy(stringBuffer, s, l);
|
2004-03-31 20:07:34 +02:00
|
|
|
}
|
2004-02-28 20:44:04 +01:00
|
|
|
|
2008-07-16 13:15:00 +02:00
|
|
|
pointer modify()
|
2008-04-18 12:03:04 +02:00
|
|
|
{
|
2004-06-27 00:23:19 +02:00
|
|
|
return stringBuffer;
|
2004-02-08 18:08:34 +01:00
|
|
|
}
|
2004-06-27 00:23:19 +02:00
|
|
|
|
|
|
|
// Trim the range making sure that it fits inside specified length
|
2008-07-16 13:15:00 +02:00
|
|
|
static void adjustRange(const size_type length, size_type& pos, size_type& n);
|
2004-06-27 00:23:19 +02:00
|
|
|
|
2008-07-16 13:15:00 +02:00
|
|
|
pointer baseAssign(const size_type n);
|
2004-06-27 00:23:19 +02:00
|
|
|
|
2008-07-16 13:15:00 +02:00
|
|
|
pointer baseAppend(const size_type n);
|
2004-06-27 00:23:19 +02:00
|
|
|
|
2009-07-31 11:17:30 +02:00
|
|
|
pointer baseInsert(const size_type p0, const size_type n);
|
2004-06-27 00:23:19 +02:00
|
|
|
|
2004-02-08 18:08:34 +01:00
|
|
|
void baseErase(size_type p0, size_type n);
|
2004-06-27 00:23:19 +02:00
|
|
|
|
2004-02-08 18:08:34 +01:00
|
|
|
enum TrimType {TrimLeft, TrimRight, TrimBoth};
|
2004-06-27 00:23:19 +02:00
|
|
|
|
2009-08-01 20:41:46 +02:00
|
|
|
void baseTrim(const TrimType whereTrim, const_pointer toTrim);
|
2006-10-29 15:16:29 +01:00
|
|
|
|
2004-02-08 18:08:34 +01:00
|
|
|
public:
|
2008-04-18 12:03:04 +02:00
|
|
|
inline const_pointer c_str() const
|
|
|
|
{
|
2004-06-27 00:23:19 +02:00
|
|
|
return stringBuffer;
|
2004-02-08 18:08:34 +01:00
|
|
|
}
|
2008-04-18 12:03:04 +02:00
|
|
|
inline size_type length() const
|
|
|
|
{
|
2004-06-27 00:23:19 +02:00
|
|
|
return stringLength;
|
2004-02-08 18:08:34 +01:00
|
|
|
}
|
2004-11-24 19:23:16 +01:00
|
|
|
// Almost same as c_str(), but return 0, not "",
|
|
|
|
// when string has no data. Useful when interacting
|
|
|
|
// with old code, which does check for NULL.
|
2008-04-18 12:03:04 +02:00
|
|
|
inline const_pointer nullStr() const
|
|
|
|
{
|
2004-11-24 19:23:16 +01:00
|
|
|
return stringLength ? stringBuffer : 0;
|
|
|
|
}
|
2004-10-07 10:35:25 +02:00
|
|
|
// Call it only when you have worked with at() or operator[]
|
|
|
|
// in case a null ASCII was inserted in the middle of the string.
|
|
|
|
inline size_type recalculate_length()
|
|
|
|
{
|
2006-10-29 15:16:29 +01:00
|
|
|
stringLength = static_cast<internal_size_type>(strlen(stringBuffer));
|
2004-10-07 10:35:25 +02:00
|
|
|
return stringLength;
|
|
|
|
}
|
2006-10-29 15:16:29 +01:00
|
|
|
|
2004-06-27 00:23:19 +02:00
|
|
|
void reserve(size_type n = 0);
|
2008-07-16 13:15:00 +02:00
|
|
|
void resize(const size_type n, char_type c = ' ');
|
2004-06-27 00:23:19 +02:00
|
|
|
|
2007-06-14 14:25:54 +02:00
|
|
|
inline pointer getBuffer(size_t l)
|
|
|
|
{
|
|
|
|
return baseAssign(l);
|
|
|
|
}
|
|
|
|
|
2009-04-17 16:10:11 +02:00
|
|
|
/*
|
|
|
|
inline void swap(AbstractString& str)
|
2008-04-18 12:03:04 +02:00
|
|
|
{
|
2004-02-08 18:08:34 +01:00
|
|
|
Storage *tmp = StringData;
|
|
|
|
StringData = str.StringData;
|
|
|
|
str.StringData = tmp;
|
2009-08-07 14:13:56 +02:00
|
|
|
}
|
|
|
|
*/
|
2002-07-05 17:00:26 +02:00
|
|
|
|
2008-04-18 12:03:04 +02:00
|
|
|
inline size_type find(const AbstractString& str, size_type pos = 0) const
|
|
|
|
{
|
2004-02-08 18:08:34 +01:00
|
|
|
return find(str.c_str(), pos);
|
|
|
|
}
|
2008-04-18 12:03:04 +02:00
|
|
|
inline size_type find(const_pointer s, size_type pos = 0) const
|
|
|
|
{
|
2004-06-27 00:23:19 +02:00
|
|
|
const_pointer p = strstr(c_str() + pos, s);
|
2004-02-08 18:08:34 +01:00
|
|
|
return p ? p - c_str() : npos;
|
|
|
|
}
|
2008-04-18 12:03:04 +02:00
|
|
|
inline size_type find(char_type c, size_type pos = 0) const
|
|
|
|
{
|
2004-06-27 00:23:19 +02:00
|
|
|
const_pointer p = strchr(c_str() + pos, c);
|
2004-02-08 18:08:34 +01:00
|
|
|
return p ? p - c_str() : npos;
|
|
|
|
}
|
2008-04-18 12:03:04 +02:00
|
|
|
inline size_type rfind(const AbstractString& str, size_type pos = npos) const
|
|
|
|
{
|
2004-02-08 18:08:34 +01:00
|
|
|
return rfind(str.c_str(), pos);
|
|
|
|
}
|
2008-07-16 13:15:00 +02:00
|
|
|
size_type rfind(const_pointer s, const size_type pos = npos) const;
|
|
|
|
size_type rfind(char_type c, const size_type pos = npos) const;
|
2008-04-18 12:03:04 +02:00
|
|
|
inline size_type find_first_of(const AbstractString& str, size_type pos = 0) const
|
|
|
|
{
|
2004-02-08 18:08:34 +01:00
|
|
|
return find_first_of(str.c_str(), pos, str.length());
|
|
|
|
}
|
|
|
|
size_type find_first_of(const_pointer s, size_type pos, size_type n) const;
|
2008-04-18 12:03:04 +02:00
|
|
|
inline size_type find_first_of(const_pointer s, size_type pos = 0) const
|
|
|
|
{
|
2004-02-08 18:08:34 +01:00
|
|
|
return find_first_of(s, pos, strlen(s));
|
|
|
|
}
|
2008-04-18 12:03:04 +02:00
|
|
|
inline size_type find_first_of(char_type c, size_type pos = 0) const
|
|
|
|
{
|
2004-02-08 18:08:34 +01:00
|
|
|
return find(c, pos);
|
|
|
|
}
|
2008-04-18 12:03:04 +02:00
|
|
|
inline size_type find_last_of(const AbstractString& str, size_type pos = npos) const
|
|
|
|
{
|
2004-02-08 18:08:34 +01:00
|
|
|
return find_last_of(str.c_str(), pos, str.length());
|
|
|
|
}
|
2008-07-16 13:15:00 +02:00
|
|
|
size_type find_last_of(const_pointer s, const size_type pos, size_type n = npos) const;
|
2008-04-18 12:03:04 +02:00
|
|
|
inline size_type find_last_of(const_pointer s, size_type pos = npos) const
|
|
|
|
{
|
2004-02-08 18:08:34 +01:00
|
|
|
return find_last_of(s, pos, strlen(s));
|
|
|
|
}
|
2008-04-18 12:03:04 +02:00
|
|
|
inline size_type find_last_of(char_type c, size_type pos = npos) const
|
|
|
|
{
|
2004-02-08 18:08:34 +01:00
|
|
|
return rfind(c, pos);
|
|
|
|
}
|
2008-04-18 12:03:04 +02:00
|
|
|
inline size_type find_first_not_of(const AbstractString& str, size_type pos = 0) const
|
|
|
|
{
|
2004-02-08 18:08:34 +01:00
|
|
|
return find_first_not_of(str.c_str(), pos, str.length());
|
|
|
|
}
|
|
|
|
size_type find_first_not_of(const_pointer s, size_type pos, size_type n) const;
|
2008-04-18 12:03:04 +02:00
|
|
|
inline size_type find_first_not_of(const_pointer s, size_type pos = 0) const
|
|
|
|
{
|
2004-02-08 18:08:34 +01:00
|
|
|
return find_first_not_of(s, pos, strlen(s));
|
|
|
|
}
|
2008-04-18 12:03:04 +02:00
|
|
|
inline size_type find_first_not_of(char_type c, size_type pos = 0) const
|
|
|
|
{
|
2008-07-16 13:15:00 +02:00
|
|
|
const char_type s[2] = {c, 0};
|
2004-02-08 18:08:34 +01:00
|
|
|
return find_first_not_of(s, pos, 1);
|
|
|
|
}
|
2008-04-18 12:03:04 +02:00
|
|
|
inline size_type find_last_not_of(const AbstractString& str, size_type pos = npos) const
|
|
|
|
{
|
2004-02-08 18:08:34 +01:00
|
|
|
return find_last_not_of(str.c_str(), pos, str.length());
|
|
|
|
}
|
2008-07-16 13:15:00 +02:00
|
|
|
size_type find_last_not_of(const_pointer s, const size_type pos, size_type n = npos) const;
|
2008-04-18 12:03:04 +02:00
|
|
|
inline size_type find_last_not_of(const_pointer s, size_type pos = npos) const
|
|
|
|
{
|
2004-02-08 18:08:34 +01:00
|
|
|
return find_last_not_of(s, pos, strlen(s));
|
|
|
|
}
|
2008-04-18 12:03:04 +02:00
|
|
|
inline size_type find_last_not_of(char_type c, size_type pos = npos) const
|
|
|
|
{
|
2008-07-16 13:15:00 +02:00
|
|
|
const char_type s[2] = {c, 0};
|
2004-02-08 18:08:34 +01:00
|
|
|
return find_last_not_of(s, pos, 1);
|
|
|
|
}
|
|
|
|
|
2008-04-18 12:03:04 +02:00
|
|
|
inline iterator begin()
|
|
|
|
{
|
2008-07-16 13:15:00 +02:00
|
|
|
return modify();
|
2004-02-08 18:08:34 +01:00
|
|
|
}
|
2008-04-18 12:03:04 +02:00
|
|
|
inline const_iterator begin() const
|
|
|
|
{
|
2004-02-08 18:08:34 +01:00
|
|
|
return c_str();
|
|
|
|
}
|
2008-04-18 12:03:04 +02:00
|
|
|
inline iterator end()
|
|
|
|
{
|
2008-07-16 13:15:00 +02:00
|
|
|
return modify() + length();
|
2004-02-08 18:08:34 +01:00
|
|
|
}
|
2008-04-18 12:03:04 +02:00
|
|
|
inline const_iterator end() const
|
|
|
|
{
|
2004-06-27 00:23:19 +02:00
|
|
|
return c_str() + length();
|
2004-02-08 18:08:34 +01:00
|
|
|
}
|
2008-07-16 13:15:00 +02:00
|
|
|
inline const_reference at(const size_type pos) const
|
2008-04-18 12:03:04 +02:00
|
|
|
{
|
2004-02-08 18:08:34 +01:00
|
|
|
checkPos(pos);
|
|
|
|
return c_str()[pos];
|
|
|
|
}
|
2008-07-16 13:15:00 +02:00
|
|
|
inline reference at(const size_type pos)
|
2008-04-18 12:03:04 +02:00
|
|
|
{
|
2004-02-08 18:08:34 +01:00
|
|
|
checkPos(pos);
|
2008-07-16 13:15:00 +02:00
|
|
|
return modify()[pos];
|
2004-02-08 18:08:34 +01:00
|
|
|
}
|
2008-04-18 12:03:04 +02:00
|
|
|
inline const_reference operator[](size_type pos) const
|
|
|
|
{
|
2004-02-08 18:08:34 +01:00
|
|
|
return at(pos);
|
|
|
|
}
|
2008-04-18 12:03:04 +02:00
|
|
|
inline reference operator[](size_type pos)
|
|
|
|
{
|
2004-02-08 18:08:34 +01:00
|
|
|
return at(pos);
|
|
|
|
}
|
2008-04-18 12:03:04 +02:00
|
|
|
inline const_pointer data() const
|
|
|
|
{
|
2004-02-08 18:08:34 +01:00
|
|
|
return c_str();
|
|
|
|
}
|
2008-04-18 12:03:04 +02:00
|
|
|
inline size_type size() const
|
|
|
|
{
|
2004-02-08 18:08:34 +01:00
|
|
|
return length();
|
|
|
|
}
|
2008-04-18 12:03:04 +02:00
|
|
|
static inline size_type max_length()
|
|
|
|
{
|
2004-06-30 01:31:12 +02:00
|
|
|
return 0xfffe; // Max length of character field in Firebird
|
2004-02-08 18:08:34 +01:00
|
|
|
}
|
2008-04-18 12:03:04 +02:00
|
|
|
inline size_type capacity() const
|
|
|
|
{
|
2009-06-03 15:13:08 +02:00
|
|
|
return bufferSize - 1u;
|
2004-02-08 18:08:34 +01:00
|
|
|
}
|
2008-04-18 12:03:04 +02:00
|
|
|
inline bool empty() const
|
|
|
|
{
|
2004-02-08 18:08:34 +01:00
|
|
|
return length() == 0;
|
|
|
|
}
|
2008-04-18 12:03:04 +02:00
|
|
|
inline bool hasData() const
|
|
|
|
{
|
2004-05-27 18:26:52 +02:00
|
|
|
return !empty();
|
|
|
|
}
|
|
|
|
// to satisfy both ways to check for empty string
|
2008-04-18 12:03:04 +02:00
|
|
|
inline bool isEmpty() const
|
|
|
|
{
|
2004-05-27 18:26:52 +02:00
|
|
|
return empty();
|
|
|
|
}
|
2004-02-08 18:08:34 +01:00
|
|
|
|
|
|
|
void upper();
|
|
|
|
void lower();
|
2008-04-18 12:03:04 +02:00
|
|
|
inline void ltrim(const_pointer ToTrim = " ")
|
|
|
|
{
|
2004-02-08 18:08:34 +01:00
|
|
|
baseTrim(TrimLeft, ToTrim);
|
|
|
|
}
|
2008-04-18 12:03:04 +02:00
|
|
|
inline void rtrim(const_pointer ToTrim = " ")
|
|
|
|
{
|
2004-02-08 18:08:34 +01:00
|
|
|
baseTrim(TrimRight, ToTrim);
|
|
|
|
}
|
2008-04-18 12:03:04 +02:00
|
|
|
inline void trim(const_pointer ToTrim = " ")
|
|
|
|
{
|
2004-02-08 18:08:34 +01:00
|
|
|
baseTrim(TrimBoth, ToTrim);
|
|
|
|
}
|
2008-04-18 12:03:04 +02:00
|
|
|
inline void alltrim(const_pointer ToTrim = " ")
|
|
|
|
{
|
2004-02-08 18:08:34 +01:00
|
|
|
baseTrim(TrimBoth, ToTrim);
|
|
|
|
}
|
2004-11-14 19:05:13 +01:00
|
|
|
|
2008-07-16 13:15:00 +02:00
|
|
|
bool LoadFromFile(FILE* file);
|
2004-10-09 02:43:04 +02:00
|
|
|
void vprintf(const char* Format, va_list params);
|
2004-03-20 15:57:40 +01:00
|
|
|
void printf(const char* Format, ...);
|
2004-11-14 19:05:13 +01:00
|
|
|
|
2006-10-29 15:16:29 +01:00
|
|
|
inline size_type copyTo(pointer to, size_type toSize) const
|
2004-11-07 15:23:36 +01:00
|
|
|
{
|
2004-11-14 19:05:13 +01:00
|
|
|
fb_assert(to);
|
|
|
|
fb_assert(toSize);
|
2004-11-07 15:23:36 +01:00
|
|
|
if (--toSize > length())
|
|
|
|
{
|
|
|
|
toSize = length();
|
|
|
|
}
|
|
|
|
memcpy(to, c_str(), toSize);
|
|
|
|
to[toSize] = 0;
|
|
|
|
return toSize;
|
|
|
|
}
|
|
|
|
|
2008-07-16 13:15:00 +02:00
|
|
|
static unsigned int hash(const_pointer string, const size_type tableSize);
|
2008-04-27 04:39:51 +02:00
|
|
|
|
2008-04-24 17:44:54 +02:00
|
|
|
inline unsigned int hash(size_type tableSize) const
|
|
|
|
{
|
|
|
|
return hash(c_str(), tableSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool equalsNoCase(const_pointer string) const;
|
|
|
|
|
2009-07-06 17:29:14 +02:00
|
|
|
inline AbstractString& append(const AbstractString& str)
|
|
|
|
{
|
|
|
|
fb_assert(&str != this);
|
|
|
|
return append(str.c_str(), str.length());
|
|
|
|
}
|
|
|
|
inline AbstractString& append(const AbstractString& str, size_type pos, size_type n)
|
|
|
|
{
|
|
|
|
fb_assert(&str != this);
|
|
|
|
adjustRange(str.length(), pos, n);
|
|
|
|
return append(str.c_str() + pos, n);
|
|
|
|
}
|
|
|
|
inline AbstractString& append(const_pointer s, const size_type n)
|
|
|
|
{
|
|
|
|
memcpy(baseAppend(n), s, n);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
inline AbstractString& append(const_pointer s)
|
|
|
|
{
|
|
|
|
return append(s, strlen(s));
|
|
|
|
}
|
|
|
|
inline AbstractString& append(size_type n, char_type c)
|
|
|
|
{
|
|
|
|
memset(baseAppend(n), c, n);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
inline AbstractString& append(const_iterator first, const_iterator last)
|
|
|
|
{
|
|
|
|
return append(first, last - first);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline AbstractString& insert(size_type p0, const AbstractString& str)
|
|
|
|
{
|
|
|
|
fb_assert(&str != this);
|
|
|
|
return insert(p0, str.c_str(), str.length());
|
|
|
|
}
|
|
|
|
inline AbstractString& insert(size_type p0, const AbstractString& str, size_type pos,
|
|
|
|
size_type n)
|
|
|
|
{
|
|
|
|
fb_assert(&str != this);
|
|
|
|
adjustRange(str.length(), pos, n);
|
|
|
|
return insert(p0, &str.c_str()[pos], n);
|
|
|
|
}
|
|
|
|
inline AbstractString& insert(size_type p0, const_pointer s, const size_type n)
|
|
|
|
{
|
|
|
|
if (p0 >= length()) {
|
|
|
|
return append(s, n);
|
|
|
|
}
|
|
|
|
memcpy(baseInsert(p0, n), s, n);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
inline AbstractString& insert(size_type p0, const_pointer s)
|
|
|
|
{
|
|
|
|
return insert(p0, s, strlen(s));
|
|
|
|
}
|
|
|
|
inline AbstractString& insert(size_type p0, const size_type n, const char_type c)
|
|
|
|
{
|
|
|
|
if (p0 >= length()) {
|
|
|
|
return append(n, c);
|
|
|
|
}
|
|
|
|
memset(baseInsert(p0, n), c, n);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
// iterator insert(iterator it, char_type c); // what to return here?
|
|
|
|
inline void insert(iterator it, size_type n, char_type c)
|
|
|
|
{
|
|
|
|
insert(it - c_str(), n, c);
|
|
|
|
}
|
|
|
|
inline void insert(iterator it, const_iterator first, const_iterator last)
|
|
|
|
{
|
|
|
|
insert(it - c_str(), first, last - first);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline AbstractString& erase(size_type p0 = 0, size_type n = npos)
|
|
|
|
{
|
|
|
|
baseErase(p0, n);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
inline iterator erase(iterator it)
|
|
|
|
{
|
|
|
|
erase(it - c_str(), 1);
|
|
|
|
return it;
|
|
|
|
}
|
|
|
|
inline iterator erase(iterator first, iterator last)
|
|
|
|
{
|
|
|
|
erase(first - c_str(), last - first);
|
|
|
|
return first;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline AbstractString& replace(size_type p0, size_type n0, const AbstractString& str)
|
|
|
|
{
|
|
|
|
fb_assert(&str != this);
|
|
|
|
return replace(p0, n0, str.c_str(), str.length());
|
|
|
|
}
|
|
|
|
inline AbstractString& replace(const size_type p0, const size_type n0,
|
|
|
|
const AbstractString& str, size_type pos, size_type n)
|
|
|
|
{
|
|
|
|
fb_assert(&str != this);
|
|
|
|
adjustRange(str.length(), pos, n);
|
|
|
|
return replace(p0, n0, &str.c_str()[pos], n);
|
|
|
|
}
|
|
|
|
inline AbstractString& replace(const size_type p0, const size_type n0, const_pointer s,
|
|
|
|
size_type n)
|
|
|
|
{
|
|
|
|
erase(p0, n0);
|
|
|
|
return insert(p0, s, n);
|
|
|
|
}
|
|
|
|
inline AbstractString& replace(size_type p0, size_type n0, const_pointer s)
|
|
|
|
{
|
|
|
|
return replace(p0, n0, s, strlen(s));
|
|
|
|
}
|
|
|
|
inline AbstractString& replace(const size_type p0, const size_type n0, size_type n,
|
|
|
|
char_type c)
|
|
|
|
{
|
|
|
|
erase(p0, n0);
|
|
|
|
return insert(p0, n, c);
|
|
|
|
}
|
|
|
|
inline AbstractString& replace(iterator first0, iterator last0, const AbstractString& str)
|
|
|
|
{
|
|
|
|
fb_assert(&str != this);
|
|
|
|
return replace(first0 - c_str(), last0 - first0, str);
|
|
|
|
}
|
|
|
|
inline AbstractString& replace(iterator first0, iterator last0, const_pointer s,
|
|
|
|
size_type n)
|
|
|
|
{
|
|
|
|
return replace(first0 - c_str(), last0 - first0, s, n);
|
|
|
|
}
|
|
|
|
inline AbstractString& replace(iterator first0, iterator last0, const_pointer s)
|
|
|
|
{
|
|
|
|
return replace(first0 - c_str(), last0 - first0, s);
|
|
|
|
}
|
|
|
|
inline AbstractString& replace(iterator first0, iterator last0, size_type n, char_type c)
|
|
|
|
{
|
|
|
|
return replace(first0 - c_str(), last0 - first0, n, c);
|
|
|
|
}
|
|
|
|
inline AbstractString& replace(iterator first0, iterator last0, const_iterator first,
|
|
|
|
const_iterator last)
|
|
|
|
{
|
|
|
|
return replace(first0 - c_str(), last0 - first0, first, last - first);
|
|
|
|
}
|
|
|
|
|
2008-04-18 12:03:04 +02:00
|
|
|
inline ~AbstractString()
|
|
|
|
{
|
2004-06-27 00:23:19 +02:00
|
|
|
if (stringBuffer != inlineBuffer)
|
|
|
|
delete[] stringBuffer;
|
2004-02-08 18:08:34 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2008-04-18 12:03:04 +02:00
|
|
|
class StringComparator
|
|
|
|
{
|
2003-05-30 14:17:47 +02:00
|
|
|
public:
|
2009-04-04 18:39:31 +02:00
|
|
|
static inline int compare(AbstractString::const_pointer s1,
|
|
|
|
AbstractString::const_pointer s2,
|
2009-04-03 14:14:07 +02:00
|
|
|
const AbstractString::size_type n)
|
2008-04-18 12:03:04 +02:00
|
|
|
{
|
2004-02-08 18:08:34 +01:00
|
|
|
return memcmp(s1, s2, n);
|
2003-05-30 14:17:47 +02:00
|
|
|
}
|
|
|
|
};
|
2008-04-18 12:03:04 +02:00
|
|
|
class PathNameComparator
|
|
|
|
{
|
2004-02-08 18:08:34 +01:00
|
|
|
public:
|
2009-04-04 18:39:31 +02:00
|
|
|
static int compare(AbstractString::const_pointer s1,
|
|
|
|
AbstractString::const_pointer s2,
|
2009-04-03 14:14:07 +02:00
|
|
|
const AbstractString::size_type n);
|
2004-02-08 18:08:34 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
template<typename Comparator>
|
2008-04-18 12:03:04 +02:00
|
|
|
class StringBase : public AbstractString
|
|
|
|
{
|
2004-02-08 18:08:34 +01:00
|
|
|
typedef StringBase<Comparator> StringType;
|
|
|
|
protected:
|
2008-12-05 01:56:15 +01:00
|
|
|
inline StringBase<Comparator>(const_pointer p1, size_type n1,
|
2004-02-08 18:08:34 +01:00
|
|
|
const_pointer p2, size_type n2) :
|
2004-12-24 09:52:39 +01:00
|
|
|
AbstractString(p1, n1, p2, n2) {}
|
2004-02-08 18:08:34 +01:00
|
|
|
private:
|
2008-04-18 12:03:04 +02:00
|
|
|
inline StringType add(const_pointer s, size_type n) const
|
|
|
|
{
|
2004-02-08 18:08:34 +01:00
|
|
|
return StringBase<Comparator>(c_str(), length(), s, n);
|
|
|
|
}
|
|
|
|
public:
|
|
|
|
inline StringBase<Comparator>() : AbstractString() {}
|
|
|
|
inline StringBase<Comparator>(const StringType& v) : AbstractString(v) {}
|
2010-01-26 16:14:47 +01:00
|
|
|
inline StringBase<Comparator>(const void* s, size_type n) : AbstractString(n, s) {}
|
2004-02-08 18:08:34 +01:00
|
|
|
inline StringBase<Comparator>(const_pointer s) : AbstractString(strlen(s), s) {}
|
2008-03-13 11:38:39 +01:00
|
|
|
inline explicit StringBase<Comparator>(const unsigned char* s) : AbstractString(strlen((char*)s), (char*)s) {}
|
2004-02-08 18:08:34 +01:00
|
|
|
inline StringBase<Comparator>(size_type n, char_type c) : AbstractString(n, c) {}
|
2008-03-13 11:38:39 +01:00
|
|
|
//inline explicit StringBase<Comparator>(char_type c) : AbstractString(1, c) {}
|
2004-02-08 18:08:34 +01:00
|
|
|
inline StringBase<Comparator>(const_iterator first, const_iterator last) : AbstractString(last - first, first) {}
|
2004-03-14 14:22:16 +01:00
|
|
|
inline explicit StringBase<Comparator>(MemoryPool& p) : AbstractString(p) {}
|
2004-03-18 06:56:06 +01:00
|
|
|
inline StringBase<Comparator>(MemoryPool& p, const AbstractString& v) : AbstractString(p, v) {}
|
2004-03-31 20:07:34 +02:00
|
|
|
inline StringBase<Comparator>(MemoryPool& p, const char_type* s, size_type l) : AbstractString(p, s, l) {}
|
|
|
|
|
2008-04-18 12:03:04 +02:00
|
|
|
inline StringType& assign(const StringType& str)
|
|
|
|
{
|
2004-02-08 18:08:34 +01:00
|
|
|
fb_assert(&str != this);
|
|
|
|
return assign(str.c_str(), str.length());
|
|
|
|
}
|
2008-04-18 12:03:04 +02:00
|
|
|
inline StringType& assign(const StringType& str, size_type pos, size_type n)
|
|
|
|
{
|
2004-02-08 18:08:34 +01:00
|
|
|
fb_assert(&str != this);
|
2008-07-16 13:15:00 +02:00
|
|
|
adjustRange(str.length(), pos, n);
|
2004-02-08 18:08:34 +01:00
|
|
|
return assign(&str.c_str()[pos], n);
|
|
|
|
}
|
2010-01-26 16:14:47 +01:00
|
|
|
inline StringType& assign(const void* s, size_type n)
|
2008-04-18 12:03:04 +02:00
|
|
|
{
|
2004-02-08 18:08:34 +01:00
|
|
|
memcpy(baseAssign(n), s, n);
|
|
|
|
return *this;
|
|
|
|
}
|
2008-04-18 12:03:04 +02:00
|
|
|
inline StringType& assign(const_pointer s)
|
|
|
|
{
|
2004-02-08 18:08:34 +01:00
|
|
|
return assign(s, strlen(s));
|
|
|
|
}
|
2008-04-18 12:03:04 +02:00
|
|
|
inline StringType& assign(size_type n, char_type c)
|
|
|
|
{
|
2004-02-08 18:08:34 +01:00
|
|
|
memset(baseAssign(n), c, n);
|
|
|
|
return *this;
|
|
|
|
}
|
2008-04-18 12:03:04 +02:00
|
|
|
inline StringType& assign(const_iterator first, const_iterator last)
|
|
|
|
{
|
2004-02-08 18:08:34 +01:00
|
|
|
return assign(first, last - first);
|
|
|
|
}
|
|
|
|
|
2008-04-18 12:03:04 +02:00
|
|
|
inline StringType& operator=(const StringType& v)
|
|
|
|
{
|
2009-10-21 02:42:38 +02:00
|
|
|
if (&v == this)
|
|
|
|
return *this;
|
2004-02-08 18:08:34 +01:00
|
|
|
return assign(v);
|
|
|
|
}
|
2008-04-18 12:03:04 +02:00
|
|
|
inline StringType& operator=(const_pointer s)
|
|
|
|
{
|
2004-02-08 18:08:34 +01:00
|
|
|
return assign(s, strlen(s));
|
|
|
|
}
|
2008-04-18 12:03:04 +02:00
|
|
|
inline StringType& operator=(char_type c)
|
|
|
|
{
|
2004-02-08 18:08:34 +01:00
|
|
|
return assign(&c, 1);
|
|
|
|
}
|
2008-04-18 12:03:04 +02:00
|
|
|
inline StringType& operator+=(const StringType& v)
|
|
|
|
{
|
2004-02-08 18:08:34 +01:00
|
|
|
fb_assert(&v != this);
|
2009-07-06 17:29:14 +02:00
|
|
|
append(v);
|
|
|
|
return *this;
|
2004-02-08 18:08:34 +01:00
|
|
|
}
|
2008-04-18 12:03:04 +02:00
|
|
|
inline StringType& operator+=(const_pointer s)
|
|
|
|
{
|
2009-07-06 17:29:14 +02:00
|
|
|
append(s);
|
|
|
|
return *this;
|
2004-02-08 18:08:34 +01:00
|
|
|
}
|
2008-04-18 12:03:04 +02:00
|
|
|
inline StringType& operator+=(char_type c)
|
|
|
|
{
|
2009-07-06 17:29:14 +02:00
|
|
|
append(1, c);
|
|
|
|
return *this;
|
2004-02-08 18:08:34 +01:00
|
|
|
}
|
2008-04-18 12:03:04 +02:00
|
|
|
inline StringType operator+(const StringType& v) const
|
|
|
|
{
|
2004-02-28 20:44:04 +01:00
|
|
|
return add(v.c_str(), v.length());
|
2004-02-08 18:08:34 +01:00
|
|
|
}
|
2008-04-18 12:03:04 +02:00
|
|
|
inline StringType operator+(const_pointer s) const
|
|
|
|
{
|
2004-02-08 18:08:34 +01:00
|
|
|
return add(s, strlen(s));
|
|
|
|
}
|
2008-04-18 12:03:04 +02:00
|
|
|
inline StringType operator+(char_type c) const
|
|
|
|
{
|
2004-02-08 18:08:34 +01:00
|
|
|
return add(&c, 1);
|
|
|
|
}
|
|
|
|
|
2008-04-18 12:03:04 +02:00
|
|
|
inline StringBase<StringComparator> ToString() const
|
|
|
|
{
|
2004-02-08 18:08:34 +01:00
|
|
|
return StringBase<StringComparator>(c_str());
|
|
|
|
}
|
2008-04-18 12:03:04 +02:00
|
|
|
inline StringBase<PathNameComparator> ToPathName() const
|
|
|
|
{
|
2004-02-08 18:08:34 +01:00
|
|
|
return StringBase<PathNameComparator>(c_str());
|
|
|
|
}
|
|
|
|
|
2008-04-18 12:03:04 +02:00
|
|
|
inline StringType substr(size_type pos = 0, size_type n = npos) const
|
|
|
|
{
|
2008-07-16 13:15:00 +02:00
|
|
|
adjustRange(length(), pos, n);
|
2004-02-08 18:08:34 +01:00
|
|
|
return StringType(&c_str()[pos], n);
|
|
|
|
}
|
2008-04-18 12:03:04 +02:00
|
|
|
inline int compare(const StringType& str) const
|
|
|
|
{
|
2004-09-17 17:02:02 +02:00
|
|
|
return compare(str.c_str(), str.length());
|
2004-02-08 18:08:34 +01:00
|
|
|
}
|
2008-04-18 12:03:04 +02:00
|
|
|
inline int compare(size_type p0, size_type n0, const StringType& str)
|
|
|
|
{
|
2004-02-08 18:08:34 +01:00
|
|
|
return compare(p0, n0, str.c_str(), str.length());
|
|
|
|
}
|
2008-04-18 12:03:04 +02:00
|
|
|
inline int compare(size_type p0, size_type n0, const StringType& str, size_type pos, size_type n)
|
|
|
|
{
|
2008-07-16 13:15:00 +02:00
|
|
|
adjustRange(str.length(), pos, n);
|
2004-02-08 18:08:34 +01:00
|
|
|
return compare(p0, n0, &str.c_str()[pos], n);
|
|
|
|
}
|
2008-04-18 12:03:04 +02:00
|
|
|
inline int compare(const_pointer s) const
|
|
|
|
{
|
2004-09-17 17:02:02 +02:00
|
|
|
return compare(s, strlen(s));
|
2004-02-08 18:08:34 +01:00
|
|
|
}
|
2008-07-16 13:15:00 +02:00
|
|
|
int compare(size_type p0, size_type n0, const_pointer s, const size_type n) const
|
2008-04-18 12:03:04 +02:00
|
|
|
{
|
2008-07-16 13:15:00 +02:00
|
|
|
adjustRange(length(), p0, n0);
|
2004-04-10 02:25:22 +02:00
|
|
|
const size_type ml = n0 < n ? n0 : n;
|
|
|
|
const int rc = Comparator::compare(&c_str()[p0], s, ml);
|
2004-09-23 09:03:14 +02:00
|
|
|
return rc ? rc : n0 - n;
|
2004-02-08 18:08:34 +01:00
|
|
|
}
|
2008-07-16 13:15:00 +02:00
|
|
|
int compare(const_pointer s, const size_type n) const
|
2008-04-18 12:03:04 +02:00
|
|
|
{
|
2004-09-17 17:02:02 +02:00
|
|
|
const size_type ml = length() < n ? length() : n;
|
|
|
|
const int rc = Comparator::compare(c_str(), s, ml);
|
2007-10-19 10:13:33 +02:00
|
|
|
if (rc)
|
|
|
|
{
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
const difference_type dl = length() - n;
|
|
|
|
return (dl < 0) ? -1 : (dl > 0) ? 1 : 0;
|
2004-09-17 17:02:02 +02:00
|
|
|
}
|
2009-08-10 00:21:31 +02:00
|
|
|
|
2009-08-07 14:13:56 +02:00
|
|
|
// These four functions are to speed up the most common comparisons: equality and inequality.
|
|
|
|
bool equals(const StringType& str) const
|
|
|
|
{
|
|
|
|
const size_type n = str.length();
|
|
|
|
return (length() != n) ? false : (Comparator::compare(c_str(), str.c_str(), n) == 0);
|
|
|
|
}
|
|
|
|
bool different(const StringType& str) const
|
|
|
|
{
|
|
|
|
const size_type n = str.length();
|
|
|
|
return (length() != n) ? true : (Comparator::compare(c_str(), str.c_str(), n) != 0);
|
|
|
|
}
|
|
|
|
bool equals(const_pointer s) const
|
|
|
|
{
|
|
|
|
const size_type n = strlen(s);
|
|
|
|
return (length() != n) ? false : (Comparator::compare(c_str(), s, n) == 0);
|
|
|
|
}
|
|
|
|
bool different(const_pointer s) const
|
|
|
|
{
|
|
|
|
const size_type n = strlen(s);
|
|
|
|
return (length() != n) ? true : (Comparator::compare(c_str(), s, n) != 0);
|
|
|
|
}
|
2004-02-08 18:08:34 +01:00
|
|
|
|
|
|
|
inline bool operator< (const StringType& str) const {return compare(str) < 0;}
|
|
|
|
inline bool operator<=(const StringType& str) const {return compare(str) <= 0;}
|
2009-08-07 14:13:56 +02:00
|
|
|
inline bool operator==(const StringType& str) const {return equals(str);}
|
2004-02-08 18:08:34 +01:00
|
|
|
inline bool operator>=(const StringType& str) const {return compare(str) >= 0;}
|
|
|
|
inline bool operator> (const StringType& str) const {return compare(str) > 0;}
|
2009-08-07 14:13:56 +02:00
|
|
|
inline bool operator!=(const StringType& str) const {return different(str);}
|
2004-03-14 14:22:16 +01:00
|
|
|
|
2004-03-31 20:07:34 +02:00
|
|
|
inline bool operator< (const char_type* str) const {return compare(str) < 0;}
|
|
|
|
inline bool operator<=(const char_type* str) const {return compare(str) <= 0;}
|
2009-08-07 14:13:56 +02:00
|
|
|
inline bool operator==(const char_type* str) const {return equals(str);}
|
2004-03-31 20:07:34 +02:00
|
|
|
inline bool operator>=(const char_type* str) const {return compare(str) >= 0;}
|
|
|
|
inline bool operator> (const char_type* str) const {return compare(str) > 0;}
|
2009-08-07 14:13:56 +02:00
|
|
|
inline bool operator!=(const char_type* str) const {return different(str);}
|
2004-02-08 18:08:34 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef StringBase<StringComparator> string;
|
2008-04-18 12:03:04 +02:00
|
|
|
inline string operator+(string::const_pointer s, const string& str)
|
|
|
|
{
|
2004-02-08 18:08:34 +01:00
|
|
|
string rc(s);
|
|
|
|
rc += str;
|
|
|
|
return rc;
|
|
|
|
}
|
2008-04-18 12:03:04 +02:00
|
|
|
inline string operator+(string::char_type c, const string& str)
|
|
|
|
{
|
2008-03-13 11:38:39 +01:00
|
|
|
string rc(1, c);
|
2004-02-08 18:08:34 +01:00
|
|
|
rc += str;
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef StringBase<PathNameComparator> PathName;
|
2008-04-18 12:03:04 +02:00
|
|
|
inline PathName operator+(PathName::const_pointer s, const PathName& str)
|
|
|
|
{
|
2004-02-08 18:08:34 +01:00
|
|
|
PathName rc(s);
|
|
|
|
rc += str;
|
|
|
|
return rc;
|
|
|
|
}
|
2008-04-18 12:03:04 +02:00
|
|
|
inline PathName operator+(PathName::char_type c, const PathName& str)
|
|
|
|
{
|
2008-03-13 11:38:39 +01:00
|
|
|
PathName rc(1, c);
|
2004-02-08 18:08:34 +01:00
|
|
|
rc += str;
|
|
|
|
return rc;
|
|
|
|
}
|
2009-02-01 23:03:10 +01:00
|
|
|
|
|
|
|
// reference-counted strings
|
|
|
|
typedef AnyRef<string> RefString;
|
|
|
|
typedef RefPtr<RefString> RefStrPtr;
|
2003-05-30 14:17:47 +02:00
|
|
|
}
|
2001-12-24 03:51:06 +01:00
|
|
|
|
2002-07-05 17:00:26 +02:00
|
|
|
|
2004-03-18 06:56:06 +01:00
|
|
|
#endif // INCLUDE_FB_STRING_H
|