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