28 static const char arraylower_t[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
29 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
30 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F,
31 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F,
32 0x40,
'a',
'b',
'c',
'd',
'e',
'f',
'g',
'h',
'i',
'j',
'k',
'l',
'm',
'n',
'o',
33 'p',
'q',
'r',
's',
't',
'u',
'v',
'w',
'x',
'y',
'z', 0x5B, 0x5C, 0x5D, 0x5E, 0x5F,
34 0x60,
'a',
'b',
'c',
'd',
'e',
'f',
'g',
'h',
'i',
'j',
'k',
'l',
'm',
'n',
'o',
35 'p',
'q',
'r',
's',
't',
'u',
'v',
'w',
'x',
'y',
'z', 0x7B, 0x7C, 0x7D, 0x7E, 0x7F
38 inline int arraylower(
int c) {
39 return arraylower_t[c];
46 return isspace(c) ?
'_' : c;
52 if ( c )
while ( *c ) ++c ;
58 for ( ; *c1 && arraylower(*c1) == arraylower(*c2); c1++, c2++)
61 return arraylower(*c1) - arraylower(*c2);
67 if ( c )
while ( *c ) ++c ;
73 for (
char *
const e = c + n ; c != e ; ++c )
79 for ( ; *c1 && arraylower(to_label(*c1)) == arraylower(to_label(*c2)); c1++, c2++)
82 return arraylower(to_label(*c1)) - arraylower(to_label(*c2));
91 namespace implementation {
121 enum { inc = 4 *
sizeof(long) };
122 static std::string::allocator_type a ;
124 const bool is_allocated = small[ max_len ] == 1;
125 const bool to_allocated = max_len < n ;
127 size_t new_alloc = 0 ;
129 if ( to_allocated && ( ! is_allocated || large.siz <= n ) ) {
130 const size_t n_total = n + 1 ;
131 new_alloc = n_total % inc ? n_total + inc - n_total % inc : n_total ;
132 if ( new_alloc == 0 || new_alloc - 1 < n ) {
133 throw std::runtime_error(
"FAILED MEMORY ALLOCATION SIZING in sierra::String");
138 char * del_ptr = NULL ;
139 size_t del_size = 0 ;
141 if ( is_allocated && ( new_alloc || ! to_allocated ) ) {
144 del_ptr = large.ptr ;
145 del_size = large.siz ;
148 if ( to_allocated ) {
156 static bool first_pass = true ;
161 if ( buf_len %
sizeof(
long) ||
163 small + max_len < (
char*)(&(large)) +
sizeof(Large) ) {
164 throw std::logic_error(
"StringData memory layout error");
170 large.siz = new_alloc ;
171 large.ptr = (
char *) a.allocate( new_alloc );
175 throw std::runtime_error(
"FAILED MEMORY ALLOCATION in sierra::String");
190 const char *
const cs_e = cs + n ;
192 while ( cs != cs_e ) *d++ = *cs++ ;
196 if ( del_ptr != NULL ) {
199 a.deallocate( del_ptr , del_size );
202 throw std::runtime_error(
"FAILED MEMORY DEALLOCATION in sierra::String");
209 StringData::~StringData()
212 StringData::StringData()
213 { small[ max_len ] = small[ off_len ] = small[ 0 ] = 0 ; }
215 size_t StringData::len()
const 216 {
return small[ max_len ] ? large.len : small[ off_len ] ; }
218 char * StringData::c_str()
219 {
return small[ max_len ] ? large.ptr : small ; }
221 const char * StringData::c_str()
const 222 {
return small[ max_len ] ? large.ptr : small ; }
228 {
return os << s.c_str(); }
232 { std::string tmp; is >> tmp; s.assign(tmp);
return is; }
236 {
return os << s.c_str(); }
240 { std::string tmp; is >> tmp; s.assign(tmp);
return is; }
static size_t length(const char *c1)
static int compare(const char *c1, const char *c2)
std::ostream & operator<<(std::ostream &s, const Bucket &k)
Print the part names for which this bucket is a subset.
static int compare(const char *c1, const char *c2)
char * mem(const char *, size_t n)
static size_t length(const char *c1)
static void convert(char *c, size_t n)