Changeset 2597


Ignore:
Timestamp:
Oct 30, 2012, 4:17:58 PM (6 years ago)
Author:
linmengl
Message:

eliminated all the strings in the code and fixed compiler flags, which makes the code super faster

Location:
proto/CSV/csv2xml
Files:
4 added
9 edited

Legend:

Unmodified
Added
Removed
  • proto/CSV/csv2xml/QA/batch_comp.sh

    r2588 r2597  
    1 for name in gen10000 #2006scores salary_data eso_eagle_awards_FY09_11.1.09  sticker-price-list FN TLTD_holdings GUNR_holdings scaledwps
     1# for name in 2006scores salary_data eso_eagle_awards_FY09_11.1.09  sticker-price-list FN TLTD_holdings GUNR_holdings scaledwps
     2# do
     3#     bash comp.sh $name
     4# done
     5
     6for name in gen1000 gen10000 #L2_2012-01 L2_2012-02
    27do
    3     bash comp.sh $name
     8    bash comp.sh $name #-tab
    49done
    510
    6 # for name in L2_2012-01 L2_2012-02
    7 # do
    8 #     bash comp.sh $name -tab
    9 # done
     11for name in L2_2012-01 L2_2012-02
     12do
     13    bash comp.sh $name -tab
     14done
  • proto/CSV/csv2xml/QA/comp.sh

    r2588 r2597  
    1313
    1414(cd ..; bash ./build.sh) # use a seperate process, won't affect the following command.
    15 xmlsh -c "csv2xml $flag $csvfile > $stdout"
    16 ../src/csv $flag $csvfile $myout
     15# xmlsh -c "csv2xml $flag $csvfile > $stdout"
     16time ../src/csv $flag $csvfile $myout
    1717
    18 diff $stdout $myout
     18# vimdiff $stdout $myout
  • proto/CSV/csv2xml/QA/test.sh

    r2590 r2597  
    33echo "Test script, compare current results with standard output"
    44
    5 for name in 2006scores salary_data eso_eagle_awards_FY09_11.1.09 sticker-price-list FN TLTD_holdings GUNR_holdings scaledwps
     5for name in spanned_escape spanned_quote 2006scores salary_data eso_eagle_awards_FY09_11.1.09 sticker-price-list FN TLTD_holdings GUNR_holdings scaledwps
    66do
    77    ../src/csv $name.csv my.xml
  • proto/CSV/csv2xml/Report.txt

    r2588 r2597  
    3939
    4040(Large CSV files are from http://openurl.ac.uk/doc/data/thedata.html)
     41
     42Appendix I:
     43Change all string into direct output
     44
     45L2_2012-01       (103.2MB) 16.761s  0.868s
     46L2_2012-02       (130.5MB) 20.117s  1.240s
     47gen1000          (28MB)    7.480s   0.824s
     48gen10000         (280MB)   59.472s  9.077s
  • proto/CSV/csv2xml/pablo_template.cpp

    r2590 r2597  
    9595static void do_process(FILE *infile, FILE *outfile);
    9696
     97const BitBlock ZERO = convert(0);
     98const BitBlock ONE = convert(1);
     99const BitBlock HIGH_ONE = bitblock::slli<BLOCK_SIZE-1>(convert(1));
     100
    97101int main(int argc, char * argv[])
    98102{
     
    100104    char outfilename[100] = "sample_xml.txt";
    101105
    102     UseTabSignal = convert(0);
     106    UseTabSignal = ZERO;
    103107    if (argc == 3)
    104108    {
     
    115119        else
    116120        {
    117             UseTabSignal = convert(1);
     121            UseTabSignal = ONE;
    118122            strcpy(infilename, argv[2]);
    119123            strcpy(outfilename, argv[3]);
     
    130134    FILE *outfile = fopen(outfilename, "w");
    131135
    132         do_process(infile, outfile);
    133 
    134         fclose(infile);
    135         fclose(outfile);
    136 
    137         return(0);
     136    do_process(infile, outfile);
     137
     138    fclose(infile);
     139    fclose(outfile);
     140
     141    return(0);
    138142}
    139143
    140 string bufToStringSimple(int startPos, int length, uint8_t *buf)
     144class BufferToXMLParser
    141145{
    142     uint8_t *p = buf + startPos;
    143     uint8_t temp = p[length];
    144     p[length] = 0;
    145     string res = (char *)p;
    146     p[length] = temp;
    147 
    148     return res;
    149 }
    150 
    151 string bufToStringWithHideSymbol(int startPos, int length, uint8_t *buf,
    152                                  BitBlockForwardIterator &hideIter)
    153 {
    154     string res = "";
     146    BitBlockForwardIterator delimIter, eolIter, andIter, hideIter;
    155147    BitBlockForwardIterator end;
    156 
    157     while (length > 0)
    158     {
    159         while (hideIter != end && *hideIter < startPos) hideIter++;
    160 
    161         if (hideIter != end && *hideIter < startPos + length)
    162         {
    163             res += bufToStringSimple(startPos, *hideIter - startPos, buf);
    164             length -= *hideIter - startPos + 1;
    165             startPos = *hideIter + 1;
    166         }
    167         else
    168         {
    169             res += bufToStringSimple(startPos, length, buf);
    170             length = 0;
    171         }
    172     }
    173 
    174     return res;
    175 }
    176 
    177 string bufToStringWithAndSymbol(int startPos, int length, uint8_t *buf,
    178                                 BitBlockForwardIterator &andIter,
    179                                 BitBlockForwardIterator &hideIter)
    180 {
    181     if (startPos + length >= BLOCK_SIZE + 1)
    182     {
    183         printf("bufToString memory leak!\n");
    184         exit(-1);
    185     }
    186 
    187     BitBlockForwardIterator end;
    188     string res = "";
    189 
    190     while (length > 0)
    191     {
    192         while ((andIter != end) && *andIter < startPos) andIter++;
    193 
    194         if (andIter != end && *andIter < startPos + length)
    195         {
    196             res += bufToStringWithHideSymbol(startPos, *andIter - startPos, buf, hideIter);
    197             res += "&amp;";
    198 
    199             length -= *andIter - startPos + 1;
    200             startPos = *andIter + 1;
    201         }
    202         else
    203         {
    204             res += bufToStringWithHideSymbol(startPos, length, buf, hideIter);
    205             length = 0;
    206         }
    207     }
    208 
    209     return res;
    210 }
    211 
    212 void parseRowWithoutLastColumn(int &pos, int endofline, BitBlockForwardIterator &delimIter,
    213                                BitBlockForwardIterator &andIter,
    214                                BitBlockForwardIterator &hideIter,
    215                                uint8_t *src_buffer, Csv2XmlWriter &writer)
    216 {
    217     BitBlockForwardIterator end;
    218     while ((delimIter != end) && (*delimIter < endofline))
    219     {
    220         int length = *delimIter - pos;
    221         writer.writeColumn(bufToStringWithAndSymbol(pos, length, src_buffer, andIter, hideIter));
    222         pos = (*delimIter) + 1;
    223 
    224         delimIter++;
    225     }
    226 }
     148    uint8_t *src_buffer;
     149    Csv2XmlWriter *writer;
     150
     151public:
     152
     153    BufferToXMLParser(Marker &marker, Lex &lex, uint8_t *buffer, Csv2XmlWriter *_writer)
     154    {
     155        delimIter = BitBlockForwardIterator(&marker.delim);
     156        eolIter = BitBlockForwardIterator(&marker.eol);
     157        andIter = BitBlockForwardIterator(&lex.AndSymbol);
     158        hideIter = BitBlockForwardIterator(&marker.hide);
     159
     160        src_buffer = buffer;
     161        writer = _writer;
     162    }
     163
     164    void parseEachRow(int buffer_size)
     165    {
     166        int pos = 0;
     167
     168        while (eolIter != end)
     169        {
     170            parseRowWithoutLastColumn(pos, *eolIter);
     171
     172            if (pos <= *eolIter)
     173            {
     174                int length = *eolIter - pos;
     175                bufPrintWithAndSymbol(pos, length);
     176                writer->nextCol();
     177            }
     178            pos = *eolIter + 1;
     179
     180            eolIter ++;
     181            writer->nextRow();
     182        }
     183
     184        if (pos <= buffer_size)
     185        {
     186            //last line within a block
     187            parseRowWithoutLastColumn(pos, buffer_size);
     188
     189            if (pos < buffer_size)
     190            {
     191                int length = buffer_size - pos;
     192                bufPrintWithAndSymbol(pos, length);
     193            }
     194        }
     195    }
     196
     197private:
     198    void parseRowWithoutLastColumn(int &pos, int endofline)
     199    {
     200        BitBlockForwardIterator end;
     201        while ((delimIter != end) && (*delimIter < endofline))
     202        {
     203            int length = *delimIter - pos;
     204            bufPrintWithAndSymbol(pos, length);
     205            writer->nextCol();
     206            pos = (*delimIter) + 1;
     207            delimIter++;
     208        }
     209    }
     210
     211    void bufPrintWithAndSymbol(int startPos, int length)
     212    {
     213        char text[10] = "&amp;";
     214
     215        if (startPos + length >= BLOCK_SIZE + 1)
     216        {
     217            printf("bufPrint memory leak!\n");
     218            exit(-1);
     219        }
     220
     221        while (length > 0)
     222        {
     223            while ((andIter != end) && *andIter < startPos) andIter++;
     224
     225            if (andIter != end && *andIter < startPos + length)
     226            {
     227                bufPrintWithHideSymbol(startPos, *andIter - startPos);
     228                writer->writeColumn(text);
     229
     230                length -= *andIter - startPos + 1;
     231                startPos = *andIter + 1;
     232            }
     233            else
     234            {
     235                bufPrintWithHideSymbol(startPos, length);
     236                length = 0;
     237            }
     238        }
     239    }
     240
     241    void bufPrintWithHideSymbol(int startPos, int length)
     242    {
     243        while (length > 0)
     244        {
     245            while (hideIter != end && *hideIter < startPos) hideIter++;
     246
     247            if (hideIter != end && *hideIter < startPos + length)
     248            {
     249                bufPrintSimple(startPos, *hideIter - startPos);
     250                length -= *hideIter - startPos + 1;
     251                startPos = *hideIter + 1;
     252            }
     253            else
     254            {
     255                bufPrintSimple(startPos, length);
     256                length = 0;
     257            }
     258        }
     259    }
     260
     261    void bufPrintSimple(int startPos, int length)
     262    {
     263        uint8_t *p = src_buffer + startPos;
     264        uint8_t temp = p[length];
     265        p[length] = 0;
     266        writer->writeColumn((char *)p);
     267        p[length] = temp;
     268    }
     269};
    227270
    228271void do_process(FILE *infile, FILE *outfile) {
     
    238281
    239282    Csv2XmlWriter writer(outfile);
    240     FlipSignal = convert(0);
     283    FlipSignal = ZERO;
    241284    //if quoted string spanned more than 1 block, next block's FlipSignal should be 1
    242285
     
    255298        }
    256299
    257         FlipSignal = convert(0);
    258         if (bitblock::any(bitblock::srli<BLOCK_SIZE-1>(marker.quote_mask)))
    259         {
    260             FlipSignal = convert(1);
     300        FlipSignal = ZERO;
     301        if (bitblock::any(simd_and(marker.quote_mask, HIGH_ONE)))
     302        {
     303            FlipSignal = ONE;
    261304        }
    262305
     
    268311        // print_register<BitBlock>("and", lex.AndSymbol);
    269312
    270         /*
    271         Write xml results
    272         */
    273         BitBlockForwardIterator delimIter(&marker.delim);
    274         BitBlockForwardIterator eolIter(&marker.eol);
    275         BitBlockForwardIterator andIter(&lex.AndSymbol);
    276         BitBlockForwardIterator hideIter(&marker.hide);
    277         BitBlockForwardIterator end;
    278         int pos = 0;
    279 
    280         while (eolIter != end)
    281         {
    282             parseRowWithoutLastColumn(pos, *eolIter, delimIter, andIter, hideIter, src_buffer, writer);
    283 
    284             if (pos <= *eolIter)
    285             {
    286                 int length = *eolIter - pos;
    287                 writer.writeColumn(bufToStringWithAndSymbol(pos, length, src_buffer, andIter, hideIter));
    288             }
    289             pos = *eolIter + 1;
    290 
    291             eolIter ++;
    292             writer.nextRow();
    293         }
    294 
    295         if (pos <= count)
    296         {
    297             //last line within a block
    298             parseRowWithoutLastColumn(pos, count, delimIter, andIter, hideIter, src_buffer, writer);
    299 
    300             if (pos <= count)
    301             {
    302                 int length = count - pos;
    303                 writer.appendColumn(bufToStringWithAndSymbol(pos, length, src_buffer, andIter, hideIter));
    304             }
    305         }
     313        BufferToXMLParser bufParser(marker, lex, src_buffer, &writer);
     314        bufParser.parseEachRow(count);
    306315    }
    307316}
  • proto/CSV/csv2xml/src/Makefile

    r2588 r2597  
    55
    66CC= g++ $(CFLAGS)
    7 CFLAGS= -g
     7CFLAGS= $(SSE) -O3
    88SSE=-msse2 #-msse4.1 -DUSE_PTEST #-mssse3 -msse4.1 -msse4.2
    99INCLUDES=-I../lib/ -I../util/
  • proto/CSV/csv2xml/src/csv.cpp

    r2590 r2597  
    287287static void do_process(FILE *infile, FILE *outfile);
    288288
     289const BitBlock ZERO = convert(0);
     290const BitBlock ONE = convert(1);
     291const BitBlock HIGH_ONE = bitblock::slli<BLOCK_SIZE-1>(convert(1));
     292
    289293int main(int argc, char * argv[])
    290294{
     
    292296    char outfilename[100] = "sample_xml.txt";
    293297
    294     UseTabSignal = convert(0);
     298    UseTabSignal = ZERO;
    295299    if (argc == 3)
    296300    {
     
    307311        else
    308312        {
    309             UseTabSignal = convert(1);
     313            UseTabSignal = ONE;
    310314            strcpy(infilename, argv[2]);
    311315            strcpy(outfilename, argv[3]);
     
    322326    FILE *outfile = fopen(outfilename, "w");
    323327
    324         do_process(infile, outfile);
    325 
    326         fclose(infile);
    327         fclose(outfile);
    328 
    329         return(0);
     328    do_process(infile, outfile);
     329
     330    fclose(infile);
     331    fclose(outfile);
     332
     333    return(0);
    330334}
    331335
    332 string bufToStringSimple(int startPos, int length, uint8_t *buf)
     336class BufferToXMLParser
    333337{
    334     uint8_t *p = buf + startPos;
    335     uint8_t temp = p[length];
    336     p[length] = 0;
    337     string res = (char *)p;
    338     p[length] = temp;
    339 
    340     return res;
    341 }
    342 
    343 string bufToStringWithHideSymbol(int startPos, int length, uint8_t *buf,
    344                                  BitBlockForwardIterator &hideIter)
    345 {
    346     string res = "";
     338    BitBlockForwardIterator delimIter, eolIter, andIter, hideIter;
    347339    BitBlockForwardIterator end;
    348 
    349     while (length > 0)
    350     {
    351         while (hideIter != end && *hideIter < startPos) hideIter++;
    352 
    353         if (hideIter != end && *hideIter < startPos + length)
    354         {
    355             res += bufToStringSimple(startPos, *hideIter - startPos, buf);
    356             length -= *hideIter - startPos + 1;
    357             startPos = *hideIter + 1;
    358         }
    359         else
    360         {
    361             res += bufToStringSimple(startPos, length, buf);
    362             length = 0;
    363         }
    364     }
    365 
    366     return res;
    367 }
    368 
    369 string bufToStringWithAndSymbol(int startPos, int length, uint8_t *buf,
    370                                 BitBlockForwardIterator &andIter,
    371                                 BitBlockForwardIterator &hideIter)
    372 {
    373     if (startPos + length >= BLOCK_SIZE + 1)
    374     {
    375         printf("bufToString memory leak!\n");
    376         exit(-1);
    377     }
    378 
    379     BitBlockForwardIterator end;
    380     string res = "";
    381 
    382     while (length > 0)
    383     {
    384         while ((andIter != end) && *andIter < startPos) andIter++;
    385 
    386         if (andIter != end && *andIter < startPos + length)
    387         {
    388             res += bufToStringWithHideSymbol(startPos, *andIter - startPos, buf, hideIter);
    389             res += "&amp;";
    390 
    391             length -= *andIter - startPos + 1;
    392             startPos = *andIter + 1;
    393         }
    394         else
    395         {
    396             res += bufToStringWithHideSymbol(startPos, length, buf, hideIter);
    397             length = 0;
    398         }
    399     }
    400 
    401     return res;
    402 }
    403 
    404 void parseRowWithoutLastColumn(int &pos, int endofline, BitBlockForwardIterator &delimIter,
    405                                BitBlockForwardIterator &andIter,
    406                                BitBlockForwardIterator &hideIter,
    407                                uint8_t *src_buffer, Csv2XmlWriter &writer)
    408 {
    409     BitBlockForwardIterator end;
    410     while ((delimIter != end) && (*delimIter < endofline))
    411     {
    412         int length = *delimIter - pos;
    413         writer.writeColumn(bufToStringWithAndSymbol(pos, length, src_buffer, andIter, hideIter));
    414         pos = (*delimIter) + 1;
    415 
    416         delimIter++;
    417     }
    418 }
     340    uint8_t *src_buffer;
     341    Csv2XmlWriter *writer;
     342
     343public:
     344
     345    BufferToXMLParser(Marker &marker, Lex &lex, uint8_t *buffer, Csv2XmlWriter *_writer)
     346    {
     347        delimIter = BitBlockForwardIterator(&marker.delim);
     348        eolIter = BitBlockForwardIterator(&marker.eol);
     349        andIter = BitBlockForwardIterator(&lex.AndSymbol);
     350        hideIter = BitBlockForwardIterator(&marker.hide);
     351
     352        src_buffer = buffer;
     353        writer = _writer;
     354    }
     355
     356    void parseEachRow(int buffer_size)
     357    {
     358        int pos = 0;
     359
     360        while (eolIter != end)
     361        {
     362            parseRowWithoutLastColumn(pos, *eolIter);
     363
     364            if (pos <= *eolIter)
     365            {
     366                int length = *eolIter - pos;
     367                bufPrintWithAndSymbol(pos, length);
     368                writer->nextCol();
     369            }
     370            pos = *eolIter + 1;
     371
     372            eolIter ++;
     373            writer->nextRow();
     374        }
     375
     376        if (pos <= buffer_size)
     377        {
     378            //last line within a block
     379            parseRowWithoutLastColumn(pos, buffer_size);
     380
     381            if (pos < buffer_size)
     382            {
     383                int length = buffer_size - pos;
     384                bufPrintWithAndSymbol(pos, length);
     385            }
     386        }
     387    }
     388
     389private:
     390    void parseRowWithoutLastColumn(int &pos, int endofline)
     391    {
     392        BitBlockForwardIterator end;
     393        while ((delimIter != end) && (*delimIter < endofline))
     394        {
     395            int length = *delimIter - pos;
     396            bufPrintWithAndSymbol(pos, length);
     397            writer->nextCol();
     398            pos = (*delimIter) + 1;
     399            delimIter++;
     400        }
     401    }
     402
     403    void bufPrintWithAndSymbol(int startPos, int length)
     404    {
     405        char text[10] = "&amp;";
     406
     407        if (startPos + length >= BLOCK_SIZE + 1)
     408        {
     409            printf("bufPrint memory leak!\n");
     410            exit(-1);
     411        }
     412
     413        while (length > 0)
     414        {
     415            while ((andIter != end) && *andIter < startPos) andIter++;
     416
     417            if (andIter != end && *andIter < startPos + length)
     418            {
     419                bufPrintWithHideSymbol(startPos, *andIter - startPos);
     420                writer->writeColumn(text);
     421
     422                length -= *andIter - startPos + 1;
     423                startPos = *andIter + 1;
     424            }
     425            else
     426            {
     427                bufPrintWithHideSymbol(startPos, length);
     428                length = 0;
     429            }
     430        }
     431    }
     432
     433    void bufPrintWithHideSymbol(int startPos, int length)
     434    {
     435        while (length > 0)
     436        {
     437            while (hideIter != end && *hideIter < startPos) hideIter++;
     438
     439            if (hideIter != end && *hideIter < startPos + length)
     440            {
     441                bufPrintSimple(startPos, *hideIter - startPos);
     442                length -= *hideIter - startPos + 1;
     443                startPos = *hideIter + 1;
     444            }
     445            else
     446            {
     447                bufPrintSimple(startPos, length);
     448                length = 0;
     449            }
     450        }
     451    }
     452
     453    void bufPrintSimple(int startPos, int length)
     454    {
     455        uint8_t *p = src_buffer + startPos;
     456        uint8_t temp = p[length];
     457        p[length] = 0;
     458        writer->writeColumn((char *)p);
     459        p[length] = temp;
     460    }
     461};
    419462
    420463void do_process(FILE *infile, FILE *outfile) {
     
    438481
    439482    Csv2XmlWriter writer(outfile);
    440     FlipSignal = convert(0);
     483    FlipSignal = ZERO;
    441484    //if quoted string spanned more than 1 block, next block's FlipSignal should be 1
    442485
     
    459502        }
    460503
    461         FlipSignal = convert(0);
    462         if (bitblock::any(bitblock::srli<BLOCK_SIZE-1>(marker.quote_mask)))
    463         {
    464             FlipSignal = convert(1);
     504        FlipSignal = ZERO;
     505        if (bitblock::any(simd_and(marker.quote_mask, HIGH_ONE)))
     506        {
     507            FlipSignal = ONE;
    465508        }
    466509
     
    472515        // print_register<BitBlock>("and", lex.AndSymbol);
    473516
    474         /*
    475         Write xml results
    476         */
    477         BitBlockForwardIterator delimIter(&marker.delim);
    478         BitBlockForwardIterator eolIter(&marker.eol);
    479         BitBlockForwardIterator andIter(&lex.AndSymbol);
    480         BitBlockForwardIterator hideIter(&marker.hide);
    481         BitBlockForwardIterator end;
    482         int pos = 0;
    483 
    484         while (eolIter != end)
    485         {
    486             parseRowWithoutLastColumn(pos, *eolIter, delimIter, andIter, hideIter, src_buffer, writer);
    487 
    488             if (pos <= *eolIter)
    489             {
    490                 int length = *eolIter - pos;
    491                 writer.writeColumn(bufToStringWithAndSymbol(pos, length, src_buffer, andIter, hideIter));
    492             }
    493             pos = *eolIter + 1;
    494 
    495             eolIter ++;
    496             writer.nextRow();
    497         }
    498 
    499         if (pos <= count)
    500         {
    501             //last line within a block
    502             parseRowWithoutLastColumn(pos, count, delimIter, andIter, hideIter, src_buffer, writer);
    503 
    504             if (pos <= count)
    505             {
    506                 int length = count - pos;
    507                 writer.appendColumn(bufToStringWithAndSymbol(pos, length, src_buffer, andIter, hideIter));
    508             }
    509         }
     517        BufferToXMLParser bufParser(marker, lex, src_buffer, &writer);
     518        bufParser.parseEachRow(count);
    510519    }
    511520}
  • proto/CSV/csv2xml/src/sample.csv

    r2590 r2597  
    1 abc,"efg,hij","&\""
    2 efh,jksd,sdf1
     1aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     2aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     3aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     4aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     5aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     6aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     7aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     8aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     9aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     10aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     11aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     12aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     13aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     14aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     15aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     16aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     17aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     18aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     19aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     20aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     21aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     22aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     23aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     24aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     25aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     26aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     27aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     28aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     29aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     30aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     31aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     32aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     33aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     34aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     35aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     36aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     37aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     38aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     39aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     40aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     41aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     42aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     43aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     44aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     45aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     46aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     47aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     48aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     49aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     50aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     51aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     52aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     53aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     54aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     55aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     56aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     57aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     58aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     59aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     60aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     61aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     62aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     63aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     64aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     65aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     66aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     67aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     68aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     69aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     70aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     71aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     72aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     73aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     74aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     75aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     76aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     77aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     78aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     79aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     80aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     81aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
     82aaaaa,aaaaaa,aaaaaaaa,aaaaaaa,aaaaaaaa,aaaaaaa
  • proto/CSV/csv2xml/util/csv2xmlwriter.hpp

    r2588 r2597  
    88#include <cstring>
    99#include <cstdlib>
    10 #include <string>
    1110using namespace std;
    1211
     
    1817    int _colStarted;
    1918    int _needClose;
    20     string currentColumn;
    2119
    2220public:
     
    2826    }
    2927
    30     Csv2XmlWriter(string filename)
     28    Csv2XmlWriter(char* filename)
    3129    {
    32         _fout = fopen(filename.c_str(), "w");
     30        _fout = fopen(filename, "w");
    3331        init();
    3432        _needClose = 1;
     
    3735    ~Csv2XmlWriter()
    3836    {
    39         if (_colStarted)
    40             writeColumnEnd();
    41 
    42         if (_rowStarted)
    43             writeRowEnd();
    44 
    4537        writeRootEnd();
    4638
     
    4941    }
    5042
    51     void writeColumn(string fullColumnContent)
     43    void writeColumn(char* fullColumnContent)
    5244    {
    53         if (!_rowStarted)
     45        if (fullColumnContent[0] == 0)
     46            return;
     47
     48        if (!_colStarted)
    5449        {
    55             writeRowStart();
    56             _rowStarted = 1;
     50            writeColumnStart();
    5751        }
    58         writeColumnStart();
    5952
    60         if (_colStarted)
    61         {
    62             fullColumnContent = currentColumn + fullColumnContent;
    63             _colStarted = 0;
    64         }
    6553        writeContent(fullColumnContent);
     54    }
     55
     56    void nextCol()
     57    {
     58        if (!_colStarted)
     59            writeColumnStart();
    6660
    6761        writeColumnEnd();
    6862    }
    6963
    70     void appendColumn(string partialColumnContent)
    71     {
    72         if (!_colStarted)
    73         {
    74             currentColumn = "";
    75             _colStarted = 1;
    76         }
    77 
    78         currentColumn += partialColumnContent;
    79     }
    80 
    8164    void nextRow()
    8265    {
     66        if (!_rowStarted)
     67            writeRowStart();
     68
    8369        writeRowEnd();
    8470    }
     
    9682    }
    9783
    98     inline void writeContent(string fullColumnContent)
     84    inline void writeContent(char* fullColumnContent)
    9985    {
    100         int n = fullColumnContent.size();
    101         fprintf(_fout, "%s", fullColumnContent.c_str());
     86        fprintf(_fout, "%s", fullColumnContent);
    10287    }
    10388
     
    116101        fprintf(_fout, "   <row>\n");
    117102        _rowDepth++;
     103        _rowStarted = 1;
    118104    }
    119105
     
    130116    inline void writeColumnStart()
    131117    {
     118        if (!_rowStarted)
     119        {
     120            writeRowStart();
     121        }
     122
    132123        fprintf(_fout, "      <col>");
    133124        _colDepth ++;
     125        _colStarted = 1;
    134126    }
    135127
Note: See TracChangeset for help on using the changeset viewer.