⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 spltest.cpp

📁 SPLASH is a c++ class library that implements many of the Perl constructs and data types, including
💻 CPP
📖 第 1 页 / 共 2 页
字号:
#ifdef	TEST

#include <iostream.h>
/*
 * V1.90
 */

#include <string.h>
#include <malloc.h>
#include <stdio.h>

#ifdef	__TURBOC__
#pragma hdrstop
#endif

#include "splash.h"

ostream& operator<<(ostream &, SPList<int> const &);

int main()
{
SPList<int> il, il1, il2, il3;
SPStringList x, y, z;
int n;

    { // test lists with pop and shift as fifos, relies on allocation being 10
    SPList<int> l(10);
    int i;

    cout << "push 0..4, then shift out" << endl;
    for(i=0;i<5;i++) l.push(i);
    cout << l << endl;
    for(i=0;i<5;i++) cout << l.shift() << ",";
    cout << "Size: " << l.count() << endl;

    cout << "push 5..11, then shift out" << endl;
    for(i=5;i<12;i++) l.push(i);
    cout << l << endl;
    for(i=0;i<7;i++) cout << l.shift() << ",";
    cout << "Size: " << l.count() << endl;

    cout << "push 12..16, then shift out" << endl;
    for(i=12;i<17;i++) l.push(i);
    cout << l << endl;
    for(i=0;i<5;i++) cout << l.shift() << ",";
    cout << "Size: " << l.count() << endl;
   
    cout << "push 17..21, then shift out" << endl;
    for(i=17;i<22;i++) l.push(i);
    cout << l << endl;
    for(i=0;i<5;i++) cout << l.shift() << ",";
    cout << "Size: " << l.count() << endl;
 
    cout << "unshift 0..4, then pop off" << endl;
    for(i=0;i<5;i++) l.unshift(i);
    cout << l << endl;
    for(i=0;i<5;i++) cout << l.pop() << ",";
    cout << "Size: " << l.count() << endl;

    cout << "unshift 5..11, then pop off" << endl;
    for(i=5;i<12;i++) l.unshift(i);
    cout << l << endl;
    for(i=0;i<7;i++) cout << l.pop() << ",";
    cout << "Size: " << l.count() << endl;
      
    cout << "unshift 12..16, then pop off" << endl;
    for(i=12;i<17;i++) l.unshift(i);
    cout << l << endl;
    for(i=0;i<5;i++) cout << l.pop() << ",";
    cout << "Size: " << l.count() << endl;
      
    cout << "unshift 17..21, then pop off" << endl;
    for(i=17;i<22;i++) l.unshift(i);
    cout << l << endl;
    for(i=0;i<5;i++) cout << l.pop() << ",";
    cout << "Size: " << l.count() << endl;
    }

    if(x) cout << "x is not empty" << endl;
    else cout << "x is empty" << endl;

    if(x.isempty()) cout << "x.isempty() is true" << endl;
    else cout << "x.isempty() is false" << endl;
     
    n= x.split("a b c d e f");

    if(x) cout << "x is not empty" << endl;
    else cout << "x is empty" << endl;

    if(x.isempty()) cout << "x.isempty() is true" << endl;
    else cout << "x.isempty() is false" << endl;

    cout << "x.split(a b c d e f)= " << n << ": " << x << endl;
    cout << "x[0] = " << x[0] << endl;
    z= x; z[0]= "x";
    cout << "z= x; z[0]=\"x\" " << "z: " << z << endl;

    SPString ss("1.2.3.4.5.6.7.8.9.0");
    y= ss.split("\\.");
    cout << "ss= " << ss << ", y= ss.split(\"\\.\"), y=" << endl << y << endl;
    cout << "y.join(\" \")" << y.join(" ") << endl;       
    {
	SPString xx= "a b c\nd e\tf   g";
        cout << xx << endl << "xx.split()= " << xx.split() << endl;
	xx= "a b c d e f g";
	cout << xx << endl << "xx.split(\",\")= " << xx.split(",") << endl;
	xx= "  a b c d e f g hi  ";
	cout << xx << endl << "xx.split(\"\")= " << xx.split("") << endl;
	xx= "a,b,c,d,,e,f,g,,,,";
	cout << xx << endl << "xx.split(\",\")= " << xx.split(",") << endl;
	xx= "a,b,c,d,,e,f,g,,";
	cout << xx << endl << "xx.split(\",\", 5)= " << xx.split(",", 5) << endl;
	xx= " a b c d e f g  ";
	cout << xx << endl << "xx.split(\" \")= " << xx.split(" ") << endl;
	xx= "a b c d,e,f g";
	cout << xx << endl << "xx.split(\"([ ,])+\")= " << xx.split("([ ,])+") << endl;
	xx= ",,,,";
	cout << xx << endl << "xx.split(\",\")= " << xx.split(",") << endl;
	xx= "";
	cout << xx << endl << "xx.split(\",\")= " << xx.split(",") << endl;
 	xx= "   a b c\td    e\nf  g   ";
	cout << xx << endl << "xx.split(\"' '\")= " << xx.split("' '") << endl;
   }

    cout << "x = " << x << endl;

    cout << "x.pop() : " << x.pop() << ", " ;
    cout << x.pop() << endl << "x= " << x << endl;;
    cout << "x.shift() : " << x.shift() << ", ";
    cout << x.shift() << endl<< "x= " << x << endl;
    
    x.unshift(y);
    cout << "x.unshift(y): " << x << endl;
    
    if(il) cout << "il is not empty" << endl;
    else cout << "il is empty" << endl;
    
    il.push(1); il.push(2); il.push(3); il.push(4);

    if(il) cout << "il is not empty" << endl;
    else cout << "il is empty" << endl;
    
    cout << "il(1, 2, 3, 4) : " << il << endl;
    il3= il; il3[0]= 9999;
    cout << "il3= il; il3[0]= 9999; il3 = " << il3 << endl << "il= " << il << endl;

    il1= il.reverse();
    cout << "il.reverse: " << il1 << endl;

    cout << "il1.sort(): " << il1.sort() << endl;

    y.reset();
    y.push("one"); y.push("two"); y.push("three"); y.push("four");
    cout << "y = " << endl << y;
    cout << "y.reverse() " << y.reverse() << endl;
    cout << "y.sort() " << y.sort() << endl;
    cout << "y.sort().reverse() " << y.sort().reverse() << endl;
        
    il2.push(3); il2.push(4);
    cout << "il2.push(3, 4) : " << il2 << endl;

    il.push(il2);    
    cout << "il.push(il2) : " << il << endl;
    
    cout << "il.pop() : " << il.pop() << ", ";
    cout << il.pop() << endl;
    
    il.unshift(il2);    
    cout << "il.unshift(il2) : " << il << endl;
    
    cout << "il.shift() : " << il.shift() << ", ";
    cout << il.shift() << endl;

    il.reset();
    il.push(1); il.push(2);
    if(il.shift() != 1) cout << "FIFO1 error" << endl;
    if(il.shift() != 2) cout << "FIFO2 error" << endl;

    for(int i=0;i<100;i++) il.push(i);
    i= 0;
    while(il){
	if(il.shift() != i)  cout << "FIFO3 error" << endl;
	i++;
    }
    if(i != 100) cout << "FIFO over/under run" << endl;
    
    cout << "testing splice:" << endl;
    x.reset();
    x.split("a b c d e f g h i");
    cout << "x = " << x << endl;
    z= x.splice(2, 3);
    cout << "z= x.splice(2, 3): z= " << z << endl << "x = " << x << endl;
    cout << "x.splice(2, 0, z): " << x.splice(2, 0, z);
    cout << "x= " << x << endl;
    cout << "z.splice(1, 1, x): " << z.splice(1, 1, x);
    cout << "z= " << z << endl;
    cout << "x= " << x << endl;
    cout << "z.splice(20, 1, x): " << z.splice(20, 1, x);
    cout << "z= " << z << endl;
    
 // test auto expand
    SPList<int> ile;
    ile[3]= 3;
    cout << ile.scalar() << ", " << ile[3] << endl;
    ile[100]= 1234;
    ile[0]= 5678;
    cout << ile.scalar() << ", " << ile[0] << ", " << ile[100] << endl;
    SPList<int> ile2;
    for(i=0;i<=100;i++) ile2[i]= i;
    for(i=200;i>100;i--) ile2[i]= i;
    for(i=0;i<=200;i++) if(ile2[i] != i) cout << "error at index " << i << endl;
    cout << "Index check done" << endl;
    cout << ile2.scalar() << ", " << ile2[0] << ", " << ile2[200] << endl;

// test Regexp stuff
    cout << endl << "testing regexp stuff:" << endl;
    x.reset();
    cout << "x.m(\".*X((...)...(...))\", \"12345Xabcxyzdef\") returns " <<
	 x.m(".*X((...)...(...))", "12345Xabcxyzdef") << endl;
    cout << "subs matched = " << x << endl;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -