home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0000 - 0009 / ibm0000-0009 / ibm0003.tar / ibm0003 / TPOWER53.ZIP / TPASM.ARC / TPCASE.ASM < prev    next >
Encoding:
Assembly Source File  |  1989-07-10  |  4.0 KB  |  159 lines

  1. ;******************************************************
  2. ;           TPCASE.ASM 5.07
  3. ;           String handling routines
  4. ;     Copyright (c) TurboPower Software 1987.
  5. ; Portions copyright (c) Sunny Hill Software 1985, 1986
  6. ;     and used under license to    TurboPower Software
  7. ;         All rights reserved.
  8. ;******************************************************
  9.  
  10.     INCLUDE    TPCOMMON.ASM
  11.  
  12. ;******************************************************    Code
  13.  
  14. CODE    SEGMENT    BYTE PUBLIC
  15.  
  16.     ASSUME    CS:CODE
  17.  
  18.     PUBLIC    Upcase,    Locase
  19.     PUBLIC    StUpcase, StLocase
  20.     PUBLIC    UpCasePrim, LoCasePrim
  21.  
  22. ;******************************************************    UpcasePrim
  23.  
  24. ;Entry : character to upcase in    AL
  25. ;Exit  : uppercase in AL
  26. ;     BX wiped out
  27.  
  28. UpCaseMap LABEL    BYTE            ;Maps international characters
  29.                     ;Starting with #129
  30.     DB    'Ü', 'É', 'A', 'Ä', 'A', 'Å', 'Ç', 'E',    'E', 'E'
  31.     DB    'I', 'I', 'I', 'Ä', 'Å', 'É', 'Æ', 'Æ',    'O', 'Ö'
  32.     DB    'O', 'U', 'U', 'Y', 'Ö', 'Ü', '¢', '£',    '¥', '₧'
  33.     DB    'ƒ', 'A', 'I', 'O', 'U', 'Ñ', 'Ñ', 'A',    'O'
  34.  
  35. UpCasePrim PROC    FAR
  36.     CMP    AL,'a'
  37.     JB    UpCaseDone        ;Done if AL < 'a'
  38.     CMP    AL,167
  39.     JA    UpCaseDone        ;Done if AL > #164
  40.     CMP    AL,'z'
  41.     JA    ExtUpCase        ;Jump if extended uppercase
  42.     SUB    AL,32            ;Convert to uppercase
  43. UpCaseDone:
  44.     RET
  45. ExtUpCase:                ;International uppercase
  46.     CMP    AL,129
  47.     JB    UpCaseDone        ;Done if AL < #129
  48.     SUB    AL,129            ;Reduce    to range of map    table
  49.     MOV    BX,OFFSET UpCaseMap
  50.     XLAT    CS:[BX]            ;Use map table
  51.     RET
  52. UpCasePrim ENDP
  53.  
  54. ;******************************************************    Upcase
  55.  
  56. ;function UpCase(Ch : Char) : Char;
  57. ;Return    uppercase of char, with    international character    support
  58.  
  59. UpCase    PROC    FAR
  60.     MOV    BX,SP
  61.     MOV    AL,SS:[BX+4]        ;AL = input character
  62.     CALL    UpcasePrim
  63.     RET    2
  64. UpCase    ENDP
  65.  
  66. ;******************************************************    LocasePrim
  67.  
  68. ;Entry : character to locase in    AL
  69. ;Exit  : lowercase in AL
  70. ;     BX wiped out
  71.  
  72. LoCaseMap LABEL    BYTE            ;Maps international characters
  73.                     ;Starting with #128
  74.     DB    'ç', 'ü', 'é', 'â', 'ä', 'à', 'å', 'ç',    'ê', 'ë'
  75.     DB    'è', 'ï', 'î', 'ì', 'ä', 'å', 'é', 'æ',    'æ', 'ô'
  76.     DB    'ö', 'ò', 'û', 'ù', 'ÿ', 'ö', 'ü', '¢',    '£', '¥'
  77.     DB    '₧', 'ƒ', 'á', 'í', 'ó', 'ú', 'ñ', 'ñ'
  78.  
  79. LoCasePrim PROC    FAR
  80.     CMP    AL,'A'
  81.     JB    LoCaseDone        ;Done if AL < 'a'
  82.     CMP    AL,165
  83.     JA    LoCaseDone        ;Done if AL > #165
  84.     CMP    AL,'Z'
  85.     JA    ExtLoCase        ;Jump if extended lowercase
  86.     ADD    AL,32            ;Convert to lowercase
  87. LoCaseDone:
  88.     RET
  89. ExtLoCase:                ;International lowercase
  90.     CMP    AL,128
  91.     JB    LoCaseDone        ;Done if AL < #128
  92.     SUB    AL,128            ;Reduce    to range of map    table
  93.     MOV    BX,OFFSET LoCaseMap
  94.     XLAT    CS:[BX]            ;Use map table
  95.     RET
  96. LoCasePrim ENDP
  97.  
  98. ;******************************************************    Locase
  99.  
  100. ;function Locase(Ch : Char) : Char;
  101. ;Return    lowercase of char, with    international character    support
  102.  
  103. LoCase    PROC    FAR
  104.     MOV    BX,SP
  105.     MOV    AL,SS:[BX+4]        ;AL = input character
  106.     CALL    LoCasePrim        ;Lowercase
  107.     RET    2
  108. LoCase    ENDP
  109.  
  110. ;******************************************************    StCase
  111. ;Convert string    to one case or another,    depending on DX
  112. StCase    PROC    FAR
  113. StCaseNear:
  114.     StackFrame
  115.     PUSH    DS
  116.     CLD                ;go forward
  117.     LDS    SI,SS:[BX+4]        ;DS:SI => S
  118.     LES    DI,SS:[BX+8]        ;ES:DI => function result
  119.     LODSB                ;AL = Length(S)
  120.     STOSB                ;Set length of result
  121.     SetZero    CH            ;CH = 0
  122.     MOV    CL,AL            ;CX = Length(S)
  123.     JCXZ    SUDone            ;Done if CX is 0
  124. SUNext:
  125.     LODSB                ;Next char into    AL
  126.     PUSH    CS            ;Fake a    FAR CALL
  127.     CALL    DX            ;Uppercase it
  128.     STOSB                ;Store char in result
  129.     LOOP    SUNext            ;repeat
  130. SUDone:
  131.     POP    DS
  132.     RET    4
  133. StCase    ENDP
  134.  
  135. ;******************************************************    StUpcase
  136.  
  137. ;function StUpcase(S : string) : string;
  138. ;Convert lower case letters in string to upper case
  139.  
  140. StUpcase PROC FAR
  141.     MOV    DX,OFFSET UpcasePrim
  142.     JMP    StCaseNear
  143. StUpcase ENDP
  144.  
  145. ;******************************************************    StLocase
  146.  
  147. ;function StLocase(S : string) : string;
  148. ;Convert upper case letters in string to lower case
  149.  
  150. StLocase PROC FAR
  151.     MOV    DX,OFFSET LocasePrim
  152.     JMP    StCaseNear
  153. StLocase ENDP
  154.  
  155.  
  156. CODE    ENDS
  157.  
  158.     END
  159.