Author Topic: Case insensitive String Compare (european character table)  (Read 2435 times)

0 Members and 1 Guest are viewing this topic.

Offline Theo Gottwald

  • Administrator
  • Hero Member
  • *****
  • Posts: 1110
  • Gender: Male
    • it-berater
Case insensitive String Compare (european character table)
« on: August 14, 2013, 12:02:03 PM »
This is a case insensitive string compare.
The Original code is from Hutch, see here:

http://www.powerbasic.com/support/pbforums/showthread.php?t=53363

i have modified the character table for european characters.
For details see attached picture.


Code: [Select]
' Originalversion Hutch:
' http://www.powerbasic.com/support/pbforums/showthread.php?t=53363
'
' Modified for european characters.
'
#COMPILE EXE
#DIM ALL

FUNCTION PBMAIN () AS LONG



END FUNCTION

                       ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

FUNCTION PBMAIN AS LONG

    str1$ = "MOV"
    str2$ = "mov"

    str3$ = "Cmp"
    str4$ = "cmpsb"

    IF bstcmpi(str1$,str2$) <> 0 THEN
      StdOut "MATCH"
    ELSE
      StdOut "NO MATCH"
    END IF

    IF bstcmpi(str3$,str4$) <> 0 THEN
      StdOut "MATCH"
    ELSE
      StdOut "NO MATCH"
    END IF

    WAITKEY$

END FUNCTION

' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

FUNCTION bstcmpi(txt1$, txt2$) AS DWORD

  ' --------------------------------------------------
  ' compare two basic dynamic strings case insensitive
  ' Return values.
  ' MATCH = 1
  ' non match = 0
  ' --------------------------------------------------
    #REGISTER NONE

    PREFIX "! "

    mov esi, txt1$                      ' copy text pointer into register
    mov edi, txt2$
    mov esi, [esi]                      ' dereference it to get text address
    mov edi, [edi]
    sub eax, eax                        ' zero eax as index

  lbl1:
    movzx edx, BYTE PTR [esi+eax]
    movzx ebx, BYTE PTR [edi+eax]
    movzx ecx, BYTE PTR Cmpi_tbl[edx]
    add eax, 1
    cmp cl, Cmpi_tbl[ebx]
    jne mismatch                        ' exit on 1st mismatch with
    test ecx, ecx                       ' test for non zero value in ECX
    jnz lbl1

    mov eax, 1                          ' set EAX to 1 for match
    jmp bye

  mismatch:
    sub eax, eax                        ' set EAX to ZERO on mismatch
    jmp bye

  ' --------------------------------
  '  German/intl. language character table   
  ' --------------------------------
  align 16
  Cmpi_tbl:
  '  0 - 15
    db   0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15
  ' 16 - 31
    db  16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31
  ' 32 - 47
    db  32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47
  ' 48 - 63
    db  48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63
  ' 64 - 79
    db  64, 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111
  ' 80 - 95
    db 112,113,114,115,116,117,118,119,120,121,122, 91, 92, 93, 94, 95
  ' 96 - 111
    db  96, 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111
  ' 112 - 127
    db 112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127
  ' 128 - 143
    db 128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143
  ' 144 - 159
    db 144,145,146,147,148,149,150,151,152,153,154,155,156,156,158,159
  ' 160 - 175
    db 160,161,162,163,164,165,166,167,168,169,170,171,172,173,173,175
  ' 176 - 191
    db 176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191
  ' 192 - 207
    db 224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239
  ' 208 - 223
    db 240,241,242,243,244,245,246,215,248,249,250,251,252,253,254,223
  ' 224 - 239
    db 224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239
  ' 240 - 255
    db 240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255

  bye:
    mov FUNCTION, eax

    END PREFIX

END FUNCTION

' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
« Last Edit: August 14, 2013, 01:05:10 PM by Theo Gottwald »