Subversion Repositories Kolibri OS

Rev

Rev 5394 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1.  proc string.length uses ebx, _str
  2.     mov     eax, 0
  3.     mov     ebx, [_str]
  4.   @@:
  5.     cmp     [ebx], byte 0
  6.     je      @f
  7.     inc     eax
  8.     inc     ebx
  9.     jmp     @b
  10.   @@:
  11.     ret
  12.  endp
  13.  
  14.  proc string.copy uses eax ebx ecx, _src, _dst
  15.     mov     eax, [_src]
  16.     mov     ebx, [_dst]
  17.   @@:
  18.     mov     cl, [eax]
  19.     mov     [ebx], cl
  20.     cmp     cl, 0
  21.     je      @f
  22.     inc     eax
  23.     inc     ebx
  24.     jmp     @b
  25.   @@:
  26.     ret
  27.  endp
  28.  
  29.  proc string.concatenate uses eax, _src, _dst
  30.     stdcall string.length, [_dst]
  31.     add     eax, [_dst]
  32.     stdcall string.copy, [_src], eax
  33.     ret
  34.  endp
  35.  
  36.  proc string.compare uses ebx ecx edx, _str1, _str2
  37.     mov     eax, 0
  38.     mov     ebx, [_str1]
  39.     mov     ecx, [_str2]
  40.   @@:
  41.     mov     dl, [ebx]
  42.     cmp     dl, [ecx]
  43.     jne     .not_eq
  44.     cmp     dl, 0
  45.     je      @f
  46.     cmp     [ecx], byte 0
  47.     je      @f
  48.     inc     ebx
  49.     inc     ecx
  50.     jmp     @b
  51.  .not_eq:
  52.     mov     eax, -1
  53.   @@:
  54.     inc     eax
  55.     ret
  56.  endp
  57.  
  58.  proc string.cmp uses ecx esi edi, _str1, _str2, _n
  59.     mov     ecx, [_n]
  60.     test    ecx, ecx         ; Max length is zero?
  61.     je      .done
  62.  
  63.     mov     esi, [_str1]        ; esi = string s1
  64.     mov     edi, [_str2]        ; edi = string s2
  65.     cld
  66.  .compare:
  67.     cmpsb                    ; Compare two bytes
  68.     jne     .done
  69.     cmp     byte [esi-1], 0  ; End of string?
  70.     je      .done
  71.     dec     ecx              ; Length limit reached?
  72.     jne     .compare
  73.  .done:
  74.     seta    al               ; al = (s1 > s2)
  75.     setb    ah               ; ah = (s1 < s2)
  76.     sub     al, ah
  77.     movsx   eax, al          ; eax = (s1 > s2) - (s1 < s2), i.e. -1, 0, 1
  78.     ret
  79.  endp
  80.  
  81.  proc string.to_lower_case uses eax, _str
  82.     mov     eax, [_str]
  83.   @@:
  84.     cmp     [eax], byte 0
  85.     je      @f
  86.     cmp     [eax], byte 65
  87.     jl      .next
  88.     cmp     [eax], byte 90
  89.     jg      .next
  90.     add     [eax], byte 97 - 65
  91.  .next:
  92.     inc     eax
  93.     jmp     @b
  94.   @@:
  95.     ret
  96.  endp
  97.  
  98.  proc string.to_upper_case uses eax, _str
  99.     mov     eax, [_str]
  100.   @@:
  101.     cmp     [eax], byte 0
  102.     je      @f
  103.     cmp     [eax], byte 97
  104.     jl      .next
  105.     cmp     [eax], byte 122
  106.     jg      .next
  107.     sub     [eax], byte 97 - 65
  108.  .next:
  109.     inc     eax
  110.     jmp     @b
  111.   @@:
  112.     ret
  113.  endp
  114.  
  115.  proc string.match uses ebx ecx edx, _str1, _str2
  116.     mov     ebx, [_str1]
  117.     mov     ecx, [_str2]
  118.   @@:
  119.     cmp     [ebx], byte 0
  120.     je      @f
  121.     cmp     [ecx], byte 0
  122.     je      @f
  123.  
  124.     mov     dl, [ebx]
  125.     cmp     [ecx], byte '?'
  126.     je      .next
  127.     cmp     [ecx], byte '*'
  128.     je      .next_ebx
  129.     cmp     [ecx], dl
  130.     je      .next
  131.  
  132.     cmp     [ecx - 1], byte '*'
  133.     je      .next_ecx
  134.  
  135.     jmp     @f
  136.  
  137.  .next_ecx:
  138.     dec     ecx
  139.     jmp     .next
  140.  .next_ebx:
  141.     dec     ebx
  142.  .next:
  143.     inc     ebx
  144.     inc     ecx
  145.     jmp     @b
  146.   @@:
  147.  
  148.   @@:
  149.     cmp     [ecx], byte 0
  150.     je      @f
  151.     cmp     [ecx], byte '*'
  152.     jne     @f
  153.     inc     ecx
  154.     jmp     @b
  155.   @@:
  156.  
  157.     cmp     [ecx], byte 0
  158.     je      @f
  159.     mov     eax, 0
  160.     ret
  161.   @@:
  162.     mov     eax, 1
  163.     ret
  164.  endp
  165.  
  166.  proc string.trim_last uses eax, _str
  167.     stdcall string.length, [_str]
  168.     add     eax, [_str]
  169.     dec     eax
  170.   @@:
  171.     cmp     [eax], byte ' '
  172.     jne     @f
  173.     mov     [eax], byte 0
  174.     dec     eax
  175.     jmp     @b
  176.   @@:
  177.     ret
  178.  endp
  179.  
  180.  proc string.trim_first, _str
  181.     mov     eax, [_str]
  182.   @@:
  183.     cmp     [eax], byte ' '
  184.     jne     @f
  185.     inc     eax
  186.     jmp     @b
  187.   @@:
  188.     ret
  189.  endp
  190.  
  191.  proc string.index_of uses ebx ecx, _str, _char, _num
  192.     mov     ebx, [_char]
  193.     mov     ecx, [_str]
  194.     mov     eax, 0
  195.   @@:
  196.     cmp     [ecx], byte 0
  197.     je      @f
  198.     cmp     [ecx], bl
  199.     jne     .after_check
  200.     dec     [_num]
  201.     jz      .finded
  202.  .after_check:
  203.     inc     ecx
  204.     inc     eax
  205.     jmp     @b
  206.   @@:
  207.     mov     eax, -1
  208.  .finded:
  209.     ret
  210.  endp
  211.  
  212.  proc string.last_index_of uses ebx ecx, _str, _char, _num
  213.     stdcall string.length, [_str]
  214.     mov     ecx, [_str]
  215.     add     ecx, eax
  216.     mov     ebx, [_char]
  217.   @@:
  218.     cmp     eax, 0
  219.     je      @f
  220.     cmp     [ecx], bl
  221.     jne     .after_check
  222.     dec     [_num]
  223.     jz      .finded
  224.  .after_check:
  225.     dec     ecx
  226.     dec     eax
  227.     jmp     @b
  228.   @@:
  229.     mov     eax, -2
  230.  .finded:
  231.     inc     eax
  232.     ret
  233.  endp