filters
- filters
- kspread
- excel
- sidewinder
31#define snprintf _snprintf
34using namespace Swinder;
37UString::Rep UString::Rep::null = { 0, 0, 1, 0 };
39static char *statBuffer = 0L;
49 if (offset < str->rep->len)
50 *(str->rep->dat + offset) = c;
55UChar& UCharReference::ref() const
57 if (offset < str->rep->len)
58 return *(str->rep->dat + offset);
61 static UChar nullRef( '\0');
68 static inline UChar* allocateChars( int s)
71 return reinterpret_cast<UChar* >( new short[s]);
76UString::Rep *UString::Rep::create( UChar *d, int l)
87UString::Rep *UString::Rep::create(UChar *d, int l, int c)
100 null.rep = &Rep::null;
106 UChar *d = allocateChars( 1 );
108 rep = Rep::create(d, 1);
113 UChar *d = allocateChars( 1 );
115 rep = Rep::create(d, 1);
128 rep = Rep::create(d, length);
135 d = allocateChars( length );
139 rep = Rep::create(d, length);
162 char buf[1+ sizeof(int)*3];
163 snprintf(buf, sizeof( int)*3, "%d", i);
164 buf[ sizeof(int)*3] = '\0';
168 static unsigned short digits[] =
169 { '9', '8', '7', '6', '5', '4', '3', '2', '1',
170 '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
172 UString::Rep* rep = 0;
176 UChar* buf = allocateChars(1);
178 rep = Rep::create(buf, 1);
183 int ndig = 1 + sizeof(int)*3;
185 UChar* buf = allocateChars(ndig);
186 UChar* ptr = buf + ndig - 1;
187 int len = (neg) ? 1 : 0;
190 for(; i != 0; i/=10, len++)
191 *ptr-- = digits[9+i%10];
197 memmove(buf, ptr+1, len* sizeof( unsigned short));
199 rep = Rep::create(buf, len, ndig);
210 char buf[1+ sizeof( unsigned int)*3];
211 snprintf(buf, sizeof( unsigned int)*3, "%d", u);
212 buf[ sizeof(int)*3] = '\0';
216 static unsigned short digits[] =
217 { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
219 UString::Rep* rep = 0;
223 UChar* buf = allocateChars(1);
225 rep = Rep::create(buf, 1);
229 int ndig = 1 + sizeof(int)*3;
230 UChar* buf = allocateChars(ndig);
231 UChar* ptr = buf + ndig - 1;
235 for(; u != 0; u/=10, len++)
236 *ptr-- = digits[u%10];
239 memmove(buf, ptr+1, len* sizeof( unsigned short));
241 rep = Rep::create(buf, len, ndig);
251 snprintf(buf, 39, "%.16g", d);
252 buf[ sizeof(int)*3] = '\0';
258 if((n >= 0) && (n < length()))
270 UChar* n = allocateChars( r );
273 rep = Rep::create(n, l, r);
289 UChar *dd = rep->data();
290 memcpy(dd+l, t. data(), tl * sizeof( UChar));
310 UChar *dd = rep->data();
311 for ( int i = 0; i < tl; i++)
312 dd[l+i].uc = static_cast<unsigned char>( s[i] );
330 UChar *dd = rep->data();
355 UChar *dd = rep->data();
356 for( int i = l-1; i >= 0; i--)
358 memcpy(dd, t. data(), tl * sizeof( UChar));
377 UChar *dd = rep->data();
378 for( int i = l-1; i >= 0; i--)
380 for( int j = 0; j < tl; j++)
381 dd[j].uc = static_cast<unsigned char>( s[j] );
397 UChar *dd = rep->data();
398 for( int i = l-1; i >= 0; i--)
414 delete [] statBuffer;
416 statBuffer = new char[ length()+1];
417 for( int i = 0; i < length(); i++)
418 statBuffer[i] = data()[i]. low();
419 statBuffer[ length()] = '\0';
427 int l = c ? strlen(c) : 0;
428 UChar *d = allocateChars( l );
429 for ( int i = 0; i < l; i++)
430 d[i].uc = static_cast<unsigned char>( c[i] );
431 rep = Rep::create(d, l);
453 for( int i = 0; i < length(); i++, u++)
465 return static_cast<const UChar * >( data() )[pos];
471 return UCharReference( this, pos);
480 else if (pos >= static_cast<int>( length() ))
484 if (pos + len >= static_cast<int>( length() ))
487 UChar *tmp = allocateChars( len );
488 memcpy(tmp, data()+pos, len * sizeof( UChar));
503 for ( const UChar *c = data() + pos; c <= end; c++)
504 if (!memcmp(c, f. data(), fsize))
510void UString::attach(Rep *r)
516void UString::detach()
522 UChar *n = allocateChars( c );
525 rep = Rep::create(n, l, c);
529void UString::release()
540 if (s1.rep->len != s2.rep->len)
543 return (memcmp(s1.rep->dat, s2.rep->dat,
544 s1.rep->len * sizeof( UChar)) == 0);
547bool Swinder::operator==( const UString& s1, const char *s2)
552 if (s1. length() != static_cast<int>( strlen(s2) ))
569 const int l1 = s1. length();
570 const int l2 = s2. length();
571 const int lmin = l1 < l2 ? l1 : l2;
575 while (l < lmin && *c1 == *c2)
596UConstString::UConstString( UChar* data, unsigned int length ) :
601UConstString::~UConstString()
605 UChar* n = allocateChars( l );
606 memcpy( n, data(), l * sizeof( UChar ) );
Dynamic reference to a string character.
UCharReference & operator=(UChar c) Set the referenced character to c.
bool is8Bit() const Use this if you want to make sure that this string is a plain ASCII string.
UString & prepend(const UString &) Prepend another string.
int find(const UString &f, int pos=0) const
static UString number(int i) Constructs a string from an int.
UString() Constructs a null string.
UString & operator=(const char *c) Assignment operator.
char * ascii() const Convert the Unicode string to plain ASCII chars chopping of any higher bytes.
UString & operator+=(const UString &s) Appends the specified string.
void truncate(int n) Truncates the string to n.
static UString null Static instance of a null string.
UString substr(int pos=0, int len=-1) const
const UChar * data() const
void reserve(int r) Reserves room for the string, useful to speed up append().
UChar operator[](int pos) const Const character at specified position.
UString & append(const UString &) Append another string.
static UChar null A static instance of UChar(0).
UChar() Construct a character with value 0.
unsigned char low() const
unsigned short unicode() const
|