~ubuntu-branches/ubuntu/wily/kbibtex/wily

« back to all changes in this revision

Viewing changes to src/encoderlatex.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michael Hanke
  • Date: 2010-07-21 12:02:48 UTC
  • mfrom: (1.1.5 upstream) (2.1.4 sid)
  • Revision ID: james.westby@ubuntu.com-20100721120248-9ohlkaiin6aktimd
Tags: 0.2.3.90-1
* New upstream release (Closes: #563684).
* Switch to source package version 3.0 (quilt).
* Bumped Standards-Version to 3.9.0, no changes necessary.
* Link against libyaz to enable Z39.50 support (Closes: #550547).

Show diffs side-by-side

added added

removed removed

Lines of Context:
334
334
        {"\\\\'", "c", 0x0107},
335
335
        /** 0x0108 */
336
336
        /** 0x0109 */
337
 
        {"\\\\v", "E", 0x010A},
338
 
        {"\\\\v", "e", 0x010B},
 
337
        /** 0x010A */
 
338
        /** 0x010B */
339
339
        {"\\\\v", "C", 0x010C},
340
340
        {"\\\\v", "c", 0x010D},
341
 
        /** 0x010E */
 
341
        {"\\\\v", "D", 0x010E},
342
342
        /** 0x010F */
343
343
        /** 0x0110 */
344
344
        /** 0x0111 */
350
350
        /** 0x0117 */
351
351
        {"\\\\c", "E", 0x0118},
352
352
        {"\\\\c", "e", 0x0119},
353
 
        /** 0x011A */
354
 
        /** 0x011B */
 
353
        {"\\\\v", "E", 0x011A},
 
354
        {"\\\\v", "e", 0x011B},
355
355
        /** 0x011C */
356
356
        /** 0x011D */
357
357
        {"\\\\u", "G", 0x011E},
368
368
        /** 0x0129 */
369
369
        /** 0x012A */
370
370
        /** 0x012B */
371
 
        /** 0x012C */
372
 
        /** 0x012D */
 
371
        {"\\\\u", "I", 0x012C},
 
372
        {"\\\\u", "i", 0x012D},
373
373
        /** 0x012E */
374
374
        /** 0x012F */
375
375
        /** 0x0130 */
381
381
        /** 0x0136 */
382
382
        /** 0x0137 */
383
383
        /** 0x0138 */
384
 
        /** 0x0139 */
385
 
        /** 0x013A */
 
384
        {"\\\\'", "L", 0x0139},
 
385
        {"\\\\'", "l", 0x013A},
386
386
        /** 0x013B */
387
387
        /** 0x013C */
388
388
        /** 0x013D */
395
395
        {"\\\\'", "n", 0x0144},
396
396
        /** 0x0145 */
397
397
        /** 0x0146 */
398
 
        /** 0x0147 */
399
 
        /** 0x0148 */
 
398
        {"\\\\v", "N", 0x0147},
 
399
        {"\\\\v", "n", 0x0148},
400
400
        /** 0x0149 */
401
401
        /** 0x014A */
402
402
        /** 0x014B */
403
403
        /** 0x014C */
404
404
        /** 0x014D */
405
 
        /** 0x014E */
406
 
        /** 0x014F */
 
405
        {"\\\\u", "O", 0x014E},
 
406
        {"\\\\u", "o", 0x014F},
407
407
        {"\\\\H", "O", 0x0150},
408
408
        {"\\\\H", "o", 0x0151},
409
409
        /** 0x0152 */
410
410
        /** 0x0153 */
411
 
        /** 0x0154 */
412
 
        /** 0x0155 */
 
411
        {"\\\\'", "R", 0x0154},
 
412
        {"\\\\'", "r", 0x0155},
413
413
        /** 0x0156 */
414
414
        /** 0x0157 */
415
 
        /** 0x0158 */
416
 
        /** 0x0159 */
 
415
        {"\\\\v", "R", 0x0158},
 
416
        {"\\\\v", "r", 0x0159},
417
417
        {"\\\\'", "S", 0x015A},
418
418
        {"\\\\'", "s", 0x015B},
419
419
        /** 0x015C */
424
424
        {"\\\\v", "s", 0x0161},
425
425
        /** 0x0162 */
426
426
        /** 0x0163 */
427
 
        /** 0x0164 */
 
427
        {"\\\\v", "T", 0x0164},
428
428
        /** 0x0165 */
429
429
        /** 0x0166 */
430
430
        /** 0x0167 */
432
432
        /** 0x0169 */
433
433
        /** 0x016A */
434
434
        /** 0x016B */
435
 
        /** 0x016C */
436
 
        /** 0x016D */
 
435
        {"\\\\u", "U", 0x016C},
 
436
        {"\\\\u", "u", 0x016D},
437
437
        {"\\\\r", "U", 0x016E},
438
438
        {"\\\\r", "u", 0x016F},
439
439
        /** 0x0170 */
475
475
    charmappingdatalatex[] =
476
476
    {
477
477
        {"\\\\#", 0x0023, "\\#"},
 
478
        {"\\\\&", 0x0026, "\\&"},
478
479
        {"\\\\_", 0x005F, "\\_"},
479
480
        {"!`", 0x00A1, "!`"},
480
481
        {"\"<", 0x00AB, "\"<"},
611
612
        const QString splitMarker = "|KBIBTEX|";
612
613
        QString result = text;
613
614
 
 
615
        /** Collect (all?) urls from the BibTeX file and store them in urls */
 
616
        /** Problem is that the replace function below will replace
 
617
          * character sequences in the URL rendering the URL invalid.
 
618
          * Later, all URLs will be replaced back to their original
 
619
          * in the hope nothing breaks ... */
 
620
        QStringList urls;
 
621
        QRegExp httpRegExp( "(ht|f)tp://[^\"} ]+" );
 
622
        httpRegExp.setMinimal( false );
 
623
        int pos = 0;
 
624
        while ( pos >= 0 )
 
625
        {
 
626
            pos = httpRegExp.search( result, pos );
 
627
            if ( pos >= 0 )
 
628
            {
 
629
                ++pos;
 
630
                QString url = httpRegExp.cap( 0 );
 
631
                urls << url;
 
632
            }
 
633
        }
 
634
 
614
635
        /** split text into math and non-math regions */
615
636
        QStringList intermediate = QStringList::split( '$', result, true );
616
637
        QStringList::Iterator it = intermediate.begin();
684
705
 
685
706
        decomposedUTF8toLaTeX( result );
686
707
 
 
708
        /** Reinserting original URLs as explained above */
 
709
        pos = 0;
 
710
        int idx = 0;
 
711
        while ( pos >= 0 )
 
712
        {
 
713
            pos = httpRegExp.search( result, pos );
 
714
            if ( pos >= 0 )
 
715
            {
 
716
                ++pos;
 
717
                int len = httpRegExp.cap( 0 ).length();
 
718
                result = result.left( pos - 1 ).append( urls[idx++] ).append( result.mid( pos + len - 1 ) );
 
719
            }
 
720
        }
 
721
 
687
722
        return result;
688
723
    }
689
724
 
819
854
        }
820
855
    }
821
856
 
 
857
    char EncoderLaTeX::unicodeToASCII( unsigned int unicode )
 
858
    {
 
859
        if ( unicode < 128 ) return ( char )unicode;
 
860
        for ( int i = 0; i < modcharmappingdatalatexcount; ++i )
 
861
            if ( modcharmappingdatalatex[i].unicode == unicode )
 
862
                return *modcharmappingdatalatex[i].letter;
 
863
        return '?';
 
864
    }
 
865
 
822
866
}