home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 2 / ctrom_ii_b.zip / ctrom_ii_b / PROGRAM / PASCAL / PERFORM / UPPERSTR.PAS < prev    next >
Pascal/Delphi Source File  |  1993-03-28  |  6KB  |  120 lines

  1. unit UpperStr;
  2. {$IFDEF VER70}
  3. {$A+,B-,D-,E-,F-,G-,I-,L-,N-,O-,P-,Q-,R-,S+,T-,V-,X+}
  4. {$ELSE}
  5. {$A+,B-,D-,E-,F-,G-,I-,L-,N-,O-,R-,S+,V-,X+}
  6. {$ENDIF}
  7. {
  8.     Borland Pascal (Objects) 7.0
  9.     Author: Bob Swart, released to Public Domain 3/93
  10.             Upper7 is based on earlier work by Max Maischein and
  11.             Wilbert van Leijen.
  12.     Code size: 123 bytes
  13.     Data size: 256 bytes
  14.     -------------------------------------------------------------------------
  15.     This unit contains a function for country specific string capitalisation.
  16. }
  17. interface
  18.  
  19.  
  20.   procedure Upper5(var Str: String);
  21.   InLine(
  22.     $8C/$DA/               {      mov   DX,DS               }
  23.     $5E/                   {      pop   SI                  }
  24.     $1F/                   {      pop   DS                  }
  25.     $FC/                   {      cld                       }
  26.     $AC/                   {      lodsb                     }
  27.     $30/$E4/               {      xor   AH,AH               }
  28.     $89/$C1/               {      mov   CX,AX               }
  29.     $E3/$12/               {      jcxz  @30                 }
  30.     $BB/Ord('a')/Ord('z')/ {      mov   BX,'za'             }
  31.     $AC/                   { @15: lodsb                     }
  32.     $38/$D8/               {      cmp   AL,BL               }
  33.     $72/$08/               {      jb    @28                 }
  34.     $38/$F8/               {      cmp   AL,BH               }
  35.     $77/$04/               {      ja    @28                 }
  36.     $80/$6C/$FF/$20/       {      sub   BYTE PTR [SI-1],$20 }
  37.     $E2/$F1/               { @28: loop  @15                 }
  38.     $8E/$DA);              { @30: mov   DS,DX               }
  39.  
  40.  
  41.   procedure Upper7(var Str: String);
  42.   { For DOS 4+ results in Country dependent string capitalisation,
  43.     otherwise results in just 'normal' ASCII string capitalisation
  44.     of the argument Str.
  45.   }
  46.  
  47.  
  48. implementation
  49. uses Dos;
  50.  
  51. Const _Table: Array[0..255] of Byte = (
  52.  { Initial values are for the 'normal' ASCII string capitalisation. }
  53.     { characters from ASCII 0 --> ASCII 96 stay the same }
  54.   00,01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,17,18,19,20,21,
  55.   22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,
  56.   44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,
  57.   66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,
  58.   88,89,90,91,92,93,94,95,96,
  59.     { characters from ASCII 97 "a" --> ASCII 122 "z" get translated }
  60.     { to characters ASCII 65 "A" --> ASCII 90 "Z" }
  61.   65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,
  62.   87,88,89,90,
  63.     { characters from ASCII 123 --> ASCII 127 stay the same }
  64.   123,124,125,126,127,
  65.     { characters from ASCII 128 --> ASCII 165 some changes }
  66.     { #129 --> #154, #130 --> #144, #132 --> #142, #134 --> #143
  67.       #135 --> #128, #145 --> #146, #148 --> #153, #164 --> #165
  68.     }
  69.   128,154,144,131,142,133,143,128,136,137,138,139,140,141,142,143,
  70.   144,146,146,147,153,149,150,151,152,153,154,155,156,157,158,159,
  71.   160,161,162,163,165,165,
  72.     { characters from ASCII 166 --> ASCII 255 stay the same }
  73.   166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,
  74.   182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,
  75.   198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,
  76.   214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,
  77.   230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,
  78.   246,247,248,249,250,251,252,253,254,255);
  79.  
  80.  
  81.   procedure Upper7(var Str: String); Assembler;
  82.   ASM
  83.         mov   DX,DS             { Save Turbo Data Segment address FAST }
  84.         xor   AX,AX             { AX = 0                               }
  85.         lds   SI,Str            { DS:SI points to Str[0]               }
  86.         cld                     { Set direction to forward             }
  87.         lodsb                   { AL = Length(Str); SI -> Str[1]       }
  88.         mov   CX,AX             { CX = Length(Str)                     }
  89.         jcxz  @Exit             { Get out if Length(Str) is zero       }
  90.         mov   BX,OFFSET _Table  { BX = Offset address of Table in DSeg }
  91.  @More: lodsb                   { Load next character into AL          }
  92.         XLAT                    { Translate char using the LookupTable }
  93.         mov   [SI-01],AL        { Save next translated char in Str     }
  94.         loop  @More             { Get next character                   }
  95.  @Exit: mov   DS,DX             { Restore Turbo's Data Segment FAST    }
  96.   end {UpperCase};
  97.  
  98.  
  99. begin
  100.   if Lo(DosVersion) > 3 then  { use DOS 4+ country specific information }
  101.   begin
  102.     for _Table[0] := 1 to 255 do _Table[_Table[0]] := _Table[0];
  103.     _Table[0] := 255;
  104.     ASM
  105.           mov   BX,DS            { Save Turbo Data Segment address FAST }
  106.           xor   AX,AX            { AX = 0                               }
  107.           mov   SI,OFFSET _Table { DS:SI points to _Table               }
  108.           cld                    { Set direction to forward             }
  109.           lodsb                  { AL = Length(_Table); SI -> _Table[1] }
  110.           mov   CX,AX            { CX = Length(_Table)                  }
  111.         { jcxz  @Exit            { Get out if Length(_Table) is zero    }
  112.           mov   DX,SI            { DS:DX points to _Table to capitalise }
  113.           mov   AX,$6521         { function $6521 = capitalise string   }
  114.           int   $21              { call DOS                             }
  115.    @Exit: mov   DS,BX            { Restore Turbo's Data Segment FAST    }
  116.     end;
  117.     _Table[0] := 0
  118.   end
  119. end.
  120.