2016-04-29 03:55:42 +00:00
# include <qse/si/sio.h>
2015-03-14 00:54:56 +00:00
# include <qse/cmn/String.hpp>
# include <qse/cmn/HeapMmgr.hpp>
2015-03-19 02:33:15 +00:00
# include <locale.h>
2015-03-14 00:54:56 +00:00
void t1 ( )
{
2018-10-31 10:40:25 +00:00
QSE : : HeapMmgr heap_mmgr ( 30000 , QSE : : Mmgr : : getDFL ( ) ) ;
2015-03-14 00:54:56 +00:00
QSE : : String * z = new QSE : : String ( ) ;
{
2018-09-18 09:02:00 +00:00
QSE : : String x ( QSE_T ( " this is a sample string " ) , & heap_mmgr ) ;
2015-03-14 00:54:56 +00:00
QSE : : String y ( x ) ;
* z = y ;
2015-03-17 16:06:07 +00:00
//z->setCharAt (0, QSE_T('Q'));
//z->prepend (QSE_T("ok."));
z - > append ( * z ) ;
for ( int i = 0 ; i < 80 ; i + + )
{
z - > prepend ( QSE_T ( " ok. " ) ) ;
z - > insert ( 10 , QSE_T ( " XXX " ) ) ;
}
z - > update ( 10 , 2 , QSE_T ( " ZZZZ " ) ) ;
//z->update (QSE_T("QQQ"));
z - > replace ( QSE_T ( " XX " ) , QSE_T ( " ^ " ) ) ;
//z->invert();
2015-03-18 13:53:22 +00:00
qse_printf ( QSE_T ( " x: [%s] [%c] capa=%d len=%d \n " ) , x . getBuffer ( ) , x [ 0u ] , ( int ) x . getCapacity ( ) , ( int ) x . getLength ( ) ) ;
qse_printf ( QSE_T ( " z: [%s] [%c] capa=%d len=%d \n " ) , z - > getBuffer ( ) , ( * z ) [ 0u ] , ( int ) z - > getCapacity ( ) , ( int ) z - > getLength ( ) ) ;
2015-03-17 16:06:07 +00:00
qse_printf ( QSE_T ( " %d %d \n " ) , ( int ) z - > findIndex ( 0 , QSE_T ( " K " ) ) , ( int ) z - > findLastIndex ( 0 , QSE_T ( " K " ) ) ) ;
2015-03-18 13:53:22 +00:00
qse_printf ( QSE_T ( " %d %d %d \n " ) , z - > beginsWith ( QSE_T ( " ok.ok " ) ) , z - > beginsWith ( QSE_T ( " ok.okX " ) ) , z - > endsWith ( QSE_T ( " string " ) ) ) ;
////////////////////////////////////////////////////
QSE : : String t ( QSE_T ( " hello world good " ) ) ;
t . trim ( ) ;
QSE_ASSERT ( t . getLength ( ) = = 20 ) ;
qse_printf ( QSE_T ( " t: [%s] %d \n " ) , t . getBuffer ( ) , t . getLength ( ) ) ;
t = QSE_T ( " come on and join me " ) ;
QSE_ASSERT ( t . getLength ( ) = = 24 ) ;
t . trimLeft ( ) ;
QSE_ASSERT ( t . getLength ( ) = = 22 ) ;
qse_printf ( QSE_T ( " t: [%s] %d \n " ) , t . getBuffer ( ) , t . getLength ( ) ) ;
t = QSE_T ( " come on and join me " ) ;
t . trimRight ( ) ;
QSE_ASSERT ( t . getLength ( ) = = 21 ) ;
qse_printf ( QSE_T ( " t: [%s] %d \n " ) , t . getBuffer ( ) , t . getLength ( ) ) ;
////////////////////////////////////////////////////
QSE : : String q ( z - > getSubstring ( 4 , 10 ) ) ;
QSE_ASSERT ( q . getLength ( ) = = 10 ) ;
QSE_ASSERT ( q . getCharAt ( 0 ) = = z - > getCharAt ( 4 ) ) ;
qse_printf ( QSE_T ( " q: [%s] %d \n " ) , q . getBuffer ( ) , q . getLength ( ) ) ;
q = z - > getSubstring ( z - > getLength ( ) - 5 ) ;
QSE_ASSERT ( q . getLength ( ) = = 5 ) ;
qse_printf ( QSE_T ( " q: [%s] %d \n " ) , q . getBuffer ( ) , q . getLength ( ) ) ;
QSE : : PercentageGrowthPolicy gp ( 1 ) ;
QSE : : String g1 ( 128 ) , g2 ( 128 ) ;
QSE_ASSERT ( g1 . getCapacity ( ) = = 128 ) ;
QSE_ASSERT ( g2 . getCapacity ( ) = = 128 ) ;
QSE_ASSERT ( g1 . getLength ( ) = = 0 ) ;
QSE_ASSERT ( g2 . getLength ( ) = = 0 ) ;
g2 . setGrowthPolicy ( & gp ) ;
for ( int i = 0 ; i < 1500 ; i + + )
{
g1 . append ( i ) ;
g2 . append ( i ) ;
}
qse_printf ( QSE_T ( " g1: %d %d g2: %d %d \n " ) , ( int ) g1 . getCapacity ( ) , ( int ) g1 . getLength ( ) , ( int ) g2 . getCapacity ( ) , ( int ) g2 . getLength ( ) ) ;
g1 . compact ( ) ;
g2 . compact ( ) ;
qse_printf ( QSE_T ( " g1: %d %d g2: %d %d \n " ) , ( int ) g1 . getCapacity ( ) , ( int ) g1 . getLength ( ) , ( int ) g2 . getCapacity ( ) , ( int ) g2 . getLength ( ) ) ;
2015-03-14 00:54:56 +00:00
}
qse_printf ( QSE_T ( " ----------------- \n " ) ) ;
delete z ;
}
2015-03-19 02:33:15 +00:00
# include <stdio.h>
2015-03-18 13:53:22 +00:00
void t2 ( )
2015-03-14 00:54:56 +00:00
{
2015-03-18 13:53:22 +00:00
QSE : : MbString x ( QSE_MT ( " this is a string " ) ) ;
2015-03-19 02:33:15 +00:00
QSE : : MbString z ( QSE_MT ( " this is a string " ) ) ;
qse_printf ( QSE_T ( " x: [%hs] capa=%d len=%d \n " ) , x . getBuffer ( ) , ( int ) x . getCapacity ( ) , ( int ) x . getLength ( ) ) ;
QSE : : MbString y ( x ) ;
y . format ( QSE_MT ( " what is this %u %u fuck i don't like [%hs] 01234567890123456789 [%lu] [%ld] " ) , ( int ) 10 , ( int ) 20 , QSE_MT ( " what is what " ) , ( unsigned long ) QSE_TYPE_MAX ( unsigned long ) , ( long ) QSE_TYPE_MAX ( long ) ) ;
qse_printf ( QSE_T ( " y: [%hs] capa=%d len=%d \n " ) , y . getBuffer ( ) , ( int ) y . getCapacity ( ) , ( int ) y . getLength ( ) ) ;
qse_size_t zl = z . getLength ( ) ;
z . append ( QSE_MT ( " is this good how do you do 0123456789 abcdefghijklmnopqrstuvwxyz AAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBVVVVVVVVVVVVVVVVVVVVVVDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD? " ) ) ;
qse_printf ( QSE_T ( " z: [%hs] capa=%d len=%d \n " ) , z . getBuffer ( ) , ( int ) z . getCapacity ( ) , ( int ) z . getLength ( ) ) ;
QSE_ASSERT ( z . getCapacity ( ) > x . getCapacity ( ) ) ;
z . remove ( zl , z . getLength ( ) - zl ) ;
QSE_ASSERT ( z . getCapacity ( ) > x . getCapacity ( ) ) ;
QSE_ASSERT ( z . getLength ( ) = = x . getLength ( ) ) ;
QSE_ASSERT ( x = = x . getBuffer ( ) ) ;
QSE_ASSERT ( x ! = y . getBuffer ( ) ) ;
QSE_ASSERT ( y = = y . getBuffer ( ) ) ;
QSE_ASSERT ( y ! = x . getBuffer ( ) ) ;
QSE_ASSERT ( x ! = y ) ;
QSE_ASSERT ( y = = y ) ;
QSE_ASSERT ( x = = z ) ;
QSE_ASSERT ( x . getBuffer ( ) ! = z . getBuffer ( ) ) ;
z . compact ( ) ;
QSE_ASSERT ( z . getCapacity ( ) = = z . getLength ( ) ) ;
QSE_ASSERT ( z . getLength ( ) = = x . getLength ( ) ) ;
qse_printf ( QSE_T ( " z: [%hs] capa=%d len=%d \n " ) , z . getBuffer ( ) , ( int ) z . getCapacity ( ) , ( int ) z . getLength ( ) ) ;
z . format ( QSE_MT ( " hello %p world " ) , z . getBuffer ( ) ) ;
qse_printf ( QSE_T ( " z: [%hs] capa=%d len=%d \n " ) , z . getBuffer ( ) , ( int ) z . getCapacity ( ) , ( int ) z . getLength ( ) ) ;
2015-03-18 13:53:22 +00:00
}
2015-03-14 00:54:56 +00:00
2015-03-18 13:53:22 +00:00
int main ( )
{
2015-03-19 02:33:15 +00:00
setlocale ( LC_ALL , " " ) ;
2017-09-16 08:54:25 +00:00
qse_open_stdsios ( ) ;
2015-03-14 00:54:56 +00:00
t1 ( ) ;
qse_printf ( QSE_T ( " ================= \n " ) ) ;
2015-03-18 13:53:22 +00:00
t2 ( ) ;
qse_printf ( QSE_T ( " ================= \n " ) ) ;
2017-09-16 08:54:25 +00:00
qse_close_stdsios ( ) ;
2015-03-14 00:54:56 +00:00
return 0 ;
}