src/corelib/ncbistr.cpp File Reference

#include <ncbi_pch.hpp>
#include <common/ncbi_source_ver.h>
#include <corelib/ncbistr.hpp>
#include <corelib/tempstr.hpp>
#include <corelib/ncbi_limits.hpp>
#include <corelib/ncbistr_util.hpp>
#include <corelib/error_codes.hpp>
#include <memory>
#include <algorithm>
#include <errno.h>
#include <stdio.h>

Include dependency graph for ncbistr.cpp:

Go to the source code of this file.

Defines

#define NCBI_USE_ERRCODE_X   Corelib_Util
#define S2N_CONVERT_ERROR(to_type, msg, errcode, force_errno, delta)
#define S2N_CONVERT_ERROR_INVAL(to_type)   S2N_CONVERT_ERROR(to_type, kEmptyStr, EINVAL, true, pos)
#define S2N_CONVERT_ERROR_RADIX(to_type, msg)   S2N_CONVERT_ERROR(to_type, msg, EINVAL, true, pos)
#define S2N_CONVERT_ERROR_OVERFLOW(to_type)   S2N_CONVERT_ERROR(to_type, "overflow",ERANGE, true, pos)
#define CHECK_ENDPTR(to_type)
#define CHECK_RANGE(nmin, nmax, to_type)
#define CHECK_RANGE_U(nmax, to_type)
#define CHECK_COMMAS
#define PRINT_INT8_CHUNK   1000000000
#define PRINT_INT8_CHUNK_SIZE   9

Enumerations

enum  ESkipMode { eSkipAll, eSkipAllAllowed, eSkipSpacesOnly }
enum  ELanguage { eLanguage_C, eLanguage_Javascript }

Functions

SIZE_TYPE s_DiffPtr (const char *end, const char *start)
bool s_IsGoodCharForRadix (char ch, int base, int *value=0)
void s_SkipAllowedSymbols (const CTempString &str, SIZE_TYPE &pos, ESkipMode skip_mode)
bool s_CheckRadix (const CTempString &str, SIZE_TYPE &pos, int &base)
static Uint8 s_DataSizeConvertQual (const CTempString &str, SIZE_TYPE &pos, Uint8 value, NStr::TStringToNumFlags flags)
static char * s_PrintUint8 (char *pos, Uint8 value, NStr::TNumToStringFlags flags, int base)
template<class TStr>
TStr s_TruncateSpaces (const TStr &str, NStr::ETrunc where, const TStr &empty_str)
template<typename T>
string s_NStr_Join (const T &arr, const string &delim)
static bool s_IsQuoted (char c, ELanguage lang)
static string s_PrintableString (const string &str, NStr::TPrintableMode mode, ELanguage lang)
static SIZE_TYPE s_EndOfTag (const string &str, SIZE_TYPE start)
static SIZE_TYPE s_EndOfReference (const string &str, SIZE_TYPE start)
static SIZE_TYPE s_VisibleWidth (const string &str, bool is_html)
char * strdup (const char *str)
 Supply string duplicate function, if one is not defined.
void s_URLDecode (const string &src, string &dst, NStr::EUrlDecode flag)
template<typename TComparator, typename TResult>
TResult s_GetField (const CTempString &str, size_t field_no, const TComparator &delimiter, NStr::EMergeDelims merge)

Variables

static const char s_Hex [] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
const char *const kEmptyCStr = ""
 Empty "C" string (points to a '').
const char *const kNcbiDevelopmentVersionString
const char *const kNcbiDevelopmentVersionString = "NCBI_DEVELOPMENT_VER_" NCBI_AS_STRING(NCBI_DEVELOPMENT_VER)
const int kMaxDoublePrecision = 308
const int kMaxDoubleStringSize = 308 + 3 + kMaxDoublePrecision
static const char * s_kTrueString = "true"
static const char * s_kFalseString = "false"
static const char * s_kTString = "t"
static const char * s_kFString = "f"
static const char * s_kYesString = "yes"
static const char * s_kNoString = "no"
static const char * s_kYString = "y"
static const char * s_kNString = "n"
static const char s_Encode [256][4]
static const char s_EncodeMarkChars [256][4]
static const char s_EncodePercentOnly [256][4]
static const char s_EncodePath [256][4]
static const char s_EncodeURIScheme [256][4]
static const char s_EncodeURIUserinfo [256][4]
static const char s_EncodeURIHost [256][4]
static const char s_EncodeURIPath [256][4]
static const char s_EncodeURIQueryName [256][4]
static const char s_EncodeURIQueryValue [256][4]
static const char s_EncodeURIFragment [256][4]
const TDelimiter & delimiter
static const TUnicodeSymbol s_cp1252_table []


Define Documentation

#define CHECK_COMMAS
 

Value:

/* Check on possible commas */                                          \
    if (flags & NStr::fAllowCommas) {                                       \
        if (ch == ',') {                                                    \
            if ((numpos == pos)  ||                                         \
                ((comma >= 0)  &&  (comma != 3)) ) {                        \
                /* Not first comma, sitting on incorrect place */           \
                break;                                                      \
            }                                                               \
            /* Skip it */                                                   \
            comma = 0;                                                      \
            pos++;                                                          \
            continue;                                                       \
        } else {                                                            \
            if (comma >= 0) {                                               \
                /* Count symbols between commas */                          \
                comma++;                                                    \
            }                                                               \
        }                                                                   \
    }

Definition at line 385 of file ncbistr.cpp.

Referenced by NStr::StringToInt8(), and NStr::StringToUInt8().

#define CHECK_ENDPTR to_type   ) 
 

Value:

if ( str[pos] ) {                                                       \
        S2N_CONVERT_ERROR(to_type, kEmptyStr, EINVAL, true, pos);           \
    }

Definition at line 370 of file ncbistr.cpp.

Referenced by NStr::StringToDoubleEx(), NStr::StringToInt8(), NStr::StringToUInt8(), and NStr::StringToUInt8_DataSize().

#define CHECK_RANGE nmin,
nmax,
to_type   ) 
 

Value:

if ( errno  ||  value < nmin  ||  value > nmax ) {                      \
        S2N_CONVERT_ERROR(to_type, "overflow", ERANGE, false, 0);           \
    }

Definition at line 375 of file ncbistr.cpp.

Referenced by NStr::StringToInt(), and NStr::StringToLong().

#define CHECK_RANGE_U nmax,
to_type   ) 
 

Value:

if ( errno  ||  value > nmax ) {                                        \
        S2N_CONVERT_ERROR(to_type, "overflow", ERANGE, false, 0);           \
    }

Definition at line 380 of file ncbistr.cpp.

Referenced by NStr::StringToUInt(), and NStr::StringToULong().

#define NCBI_USE_ERRCODE_X   Corelib_Util
 

Definition at line 46 of file ncbistr.cpp.

#define PRINT_INT8_CHUNK   1000000000
 

Definition at line 1019 of file ncbistr.cpp.

Referenced by s_PrintUint8().

#define PRINT_INT8_CHUNK_SIZE   9
 

Definition at line 1020 of file ncbistr.cpp.

Referenced by s_PrintUint8().

#define S2N_CONVERT_ERROR to_type,
msg,
errcode,
force_errno,
delta   ) 
 

Value:

if (flags & NStr::fConvErr_NoThrow)  {                              \
            if ( force_errno )                                              \
                errno = 0;                                                  \
            if ( !errno )                                                   \
                errno = errcode;                                            \
            /* ignore previosly converted value -- always return zero */    \
            return 0;                                                       \
        } else {                                                            \
            CTempString str_tmp(str);                                       \
            CTempString msg_tmp(msg);                                       \
            string smsg;                                                    \
            smsg.reserve(str_tmp.length() + msg_tmp.length() + 50);         \
            smsg += "Cannot convert string '";                              \
            smsg += str;                                                    \
            smsg += "' to " #to_type;                                       \
            if ( !msg_tmp.empty() ) {                                       \
                smsg += ", ";                                               \
                smsg += msg;                                                \
            }                                                               \
            NCBI_THROW2(CStringException, eConvert, smsg, delta);           \
        }                                                                   \

Definition at line 338 of file ncbistr.cpp.

Referenced by NStr::StringToDoubleEx().

#define S2N_CONVERT_ERROR_INVAL to_type   )     S2N_CONVERT_ERROR(to_type, kEmptyStr, EINVAL, true, pos)
 

Definition at line 361 of file ncbistr.cpp.

Referenced by s_DataSizeConvertQual(), NStr::StringToDoubleEx(), NStr::StringToInt8(), NStr::StringToUInt8(), and NStr::StringToUInt8_DataSize().

#define S2N_CONVERT_ERROR_OVERFLOW to_type   )     S2N_CONVERT_ERROR(to_type, "overflow",ERANGE, true, pos)
 

Definition at line 367 of file ncbistr.cpp.

Referenced by s_DataSizeConvertQual(), NStr::StringToInt8(), and NStr::StringToUInt8().

#define S2N_CONVERT_ERROR_RADIX to_type,
msg   )     S2N_CONVERT_ERROR(to_type, msg, EINVAL, true, pos)
 

Definition at line 364 of file ncbistr.cpp.

Referenced by NStr::StringToInt8(), NStr::StringToUInt8(), and NStr::StringToUInt8_DataSize().


Enumeration Type Documentation

enum ELanguage
 

Enumerator:
eLanguage_C 
eLanguage_Javascript 

Definition at line 1863 of file ncbistr.cpp.

enum ESkipMode
 

Enumerator:
eSkipAll 
eSkipAllAllowed 
eSkipSpacesOnly 

Definition at line 470 of file ncbistr.cpp.


Function Documentation

bool s_CheckRadix const CTempString str,
SIZE_TYPE pos,
int &  base
 

Definition at line 500 of file ncbistr.cpp.

Referenced by NStr::StringToInt8(), NStr::StringToUInt8(), and NStr::StringToUInt8_DataSize().

static Uint8 s_DataSizeConvertQual const CTempString str,
SIZE_TYPE pos,
Uint8  value,
NStr::TStringToNumFlags  flags
[static]
 

Definition at line 764 of file ncbistr.cpp.

References kMax_UI8, S2N_CONVERT_ERROR_INVAL, and S2N_CONVERT_ERROR_OVERFLOW.

Referenced by NStr::StringToUInt8_DataSize().

SIZE_TYPE s_DiffPtr const char *  end,
const char *  start
[inline]
 

Definition at line 56 of file ncbistr.cpp.

Referenced by CStringUTF8::GetSymbolCount(), and NStr::StringToDoubleEx().

static SIZE_TYPE s_EndOfReference const string &  str,
SIZE_TYPE  start
[static]
 

Definition at line 2170 of file ncbistr.cpp.

References _ASSERT, and NPOS.

Referenced by s_VisibleWidth().

static SIZE_TYPE s_EndOfTag const string &  str,
SIZE_TYPE  start
[static]
 

Definition at line 2131 of file ncbistr.cpp.

References _ASSERT, NCBI_THROW2, and NPOS.

Referenced by s_VisibleWidth().

template<typename TComparator, typename TResult>
TResult @0::s_GetField const CTempString str,
size_t  field_no,
const TComparator &  delimiter,
NStr::EMergeDelims  merge
[static]
 

Definition at line 3094 of file ncbistr.cpp.

References CTempString::data(), delimiter, NStr::eMergeDelims, and CTempString::length().

Referenced by s_SearchSortedArray(), and CGeneInfoFileReader::x_GeneIdToOffset().

bool s_IsGoodCharForRadix char  ch,
int  base,
int *  value = 0
 

Definition at line 448 of file ncbistr.cpp.

Referenced by NStr::StringToInt8(), NStr::StringToUInt8(), and NStr::StringToUInt8_DataSize().

static bool s_IsQuoted char  c,
ELanguage  lang
[inline, static]
 

Definition at line 1869 of file ncbistr.cpp.

template<typename T>
string s_NStr_Join const T &  arr,
const string &  delim
 

Definition at line 1828 of file ncbistr.cpp.

References kEmptyStr.

Referenced by NStr::Join().

static string s_PrintableString const string &  str,
NStr::TPrintableMode  mode,
ELanguage  lang
[static]
 

Definition at line 1879 of file ncbistr.cpp.

References NStr::fNewLine_Passthru, and out().

Referenced by NStr::JavaScriptEncode(), and NStr::PrintableString().

static char* s_PrintUint8 char *  pos,
Uint8  value,
NStr::TNumToStringFlags  flags,
int  base
[static]
 

Definition at line 1023 of file ncbistr.cpp.

References NStr::fWithCommas, PRINT_INT8_CHUNK, PRINT_INT8_CHUNK_SIZE, and s_Hex.

Referenced by NStr::Int8ToString(), and NStr::UInt8ToString().

void s_SkipAllowedSymbols const CTempString str,
SIZE_TYPE pos,
ESkipMode  skip_mode
 

Definition at line 476 of file ncbistr.cpp.

References eSkipAll, len, and CTempString::length().

Referenced by NStr::StringToDoubleEx(), NStr::StringToInt8(), NStr::StringToUInt8(), and NStr::StringToUInt8_DataSize().

template<class TStr>
TStr s_TruncateSpaces const TStr &  str,
NStr::ETrunc  where,
const TStr &  empty_str
 

Definition at line 1424 of file ncbistr.cpp.

References _ASSERT, NStr::eTrunc_Begin, NStr::eTrunc_Both, and NStr::eTrunc_End.

Referenced by NStr::TruncateSpaces().

void s_URLDecode const string &  src,
string &  dst,
NStr::EUrlDecode  flag
 

Definition at line 2928 of file ncbistr.cpp.

References len.

Referenced by NStr::URLDecode(), NStr::URLDecodeInPlace(), and CGFFReader::x_ParseV3Attributes().

static SIZE_TYPE s_VisibleWidth const string &  str,
bool  is_html
[static]
 

Definition at line 2188 of file ncbistr.cpp.

References NPOS, s_EndOfReference(), and s_EndOfTag().

Referenced by NStr::Wrap().


Variable Documentation

const TDelimiter& delimiter
 

Definition at line 3071 of file ncbistr.cpp.

Referenced by ct_cursor(), main(), and s_GetField().

const int kMaxDoublePrecision = 308
 

Definition at line 1181 of file ncbistr.cpp.

const int kMaxDoubleStringSize = 308 + 3 + kMaxDoublePrecision
 

Definition at line 1185 of file ncbistr.cpp.

const char* const kNcbiDevelopmentVersionString = "NCBI_DEVELOPMENT_VER_" NCBI_AS_STRING(NCBI_DEVELOPMENT_VER)
 

Definition at line 66 of file ncbistr.cpp.

const char* const kNcbiDevelopmentVersionString
 

Definition at line 66 of file ncbistr.cpp.

const TUnicodeSymbol s_cp1252_table[] [static]
 

Initial value:

 {
    0x20AC, 0x003F, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
    0x02C6, 0x2030, 0x0160, 0x2039, 0x0152, 0x003F, 0x017D, 0x003F,
    0x003F, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
    0x02DC, 0x2122, 0x0161, 0x203A, 0x0153, 0x003F, 0x017E, 0x0178
}

Definition at line 3354 of file ncbistr.cpp.

const char s_Encode[256][4] [static]
 

Definition at line 2446 of file ncbistr.cpp.

const char s_EncodeMarkChars[256][4] [static]
 

Definition at line 2481 of file ncbistr.cpp.

const char s_EncodePath[256][4] [static]
 

Definition at line 2551 of file ncbistr.cpp.

const char s_EncodePercentOnly[256][4] [static]
 

Definition at line 2516 of file ncbistr.cpp.

const char s_EncodeURIFragment[256][4] [static]
 

Definition at line 2796 of file ncbistr.cpp.

const char s_EncodeURIHost[256][4] [static]
 

Definition at line 2656 of file ncbistr.cpp.

const char s_EncodeURIPath[256][4] [static]
 

Definition at line 2691 of file ncbistr.cpp.

const char s_EncodeURIQueryName[256][4] [static]
 

Definition at line 2726 of file ncbistr.cpp.

const char s_EncodeURIQueryValue[256][4] [static]
 

Definition at line 2761 of file ncbistr.cpp.

const char s_EncodeURIScheme[256][4] [static]
 

Definition at line 2586 of file ncbistr.cpp.

const char s_EncodeURIUserinfo[256][4] [static]
 

Definition at line 2621 of file ncbistr.cpp.

const char s_Hex[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" [static]
 

Definition at line 53 of file ncbistr.cpp.

Referenced by NStr::IntToString(), s_PrintUint8(), and NStr::UIntToString().

const char* s_kFalseString = "false" [static]
 

Definition at line 1279 of file ncbistr.cpp.

const char* s_kFString = "f" [static]
 

Definition at line 1281 of file ncbistr.cpp.

const char* s_kNoString = "no" [static]
 

Definition at line 1283 of file ncbistr.cpp.

const char* s_kNString = "n" [static]
 

Definition at line 1285 of file ncbistr.cpp.

const char* s_kTrueString = "true" [static]
 

Definition at line 1278 of file ncbistr.cpp.

const char* s_kTString = "t" [static]
 

Definition at line 1280 of file ncbistr.cpp.

const char* s_kYesString = "yes" [static]
 

Definition at line 1282 of file ncbistr.cpp.

const char* s_kYString = "y" [static]
 

Definition at line 1284 of file ncbistr.cpp.


Generated on Wed Dec 9 07:44:18 2009 for NCBI C++ ToolKit by  doxygen 1.4.6
Modified on Wed Dec 09 08:18:34 2009 by modify_doxy.py rev. 173732