klisp

an open source interpreter for the Kernel Programming Language.
git clone http://git.hanabi.in/repos/klisp.git
Log | Files | Refs | README

commit 453c2e4a9931ec6b6ec4885138aaa8e1f11b8b31
parent 68d4ef952a9f2cf074189b309fd52ce2126d8001
Author: Andres Navarro <canavarro82@gmail.com>
Date:   Sun, 10 Apr 2011 22:04:53 -0300

Refactored kstring_lep, kstring_gtp and kstring_gep to use kstring_ltp and
	   kstring_ci_lep, kstring_ci_gtp, kstring_ci_gep to use kstring_ci_ltp.

Diffstat:
Msrc/kgstrings.c | 86++++++-------------------------------------------------------------------------
1 file changed, 6 insertions(+), 80 deletions(-)

diff --git a/src/kgstrings.c b/src/kgstrings.c @@ -186,41 +186,9 @@ bool kstring_ltp(TValue str1, TValue str2) return (res < 0 || (res == 0 && size1 < size2)); } -bool kstring_lep(TValue str1, TValue str2) -{ - int32_t size1 = kstring_size(str1); - int32_t size2 = kstring_size(str2); - - int32_t min_size = size1 < size2? size1 : size2; - /* memcmp > 0 if str1 has a bigger char in first diff position */ - int res = memcmp(kstring_buf(str1), kstring_buf(str2), min_size); - - return (res < 0 || (res == 0 && size1 <= size2)); -} - -bool kstring_gtp(TValue str1, TValue str2) -{ - int32_t size1 = kstring_size(str1); - int32_t size2 = kstring_size(str2); - - int32_t min_size = size1 < size2? size1 : size2; - /* memcmp > 0 if str1 has a bigger char in first diff position */ - int res = memcmp(kstring_buf(str1), kstring_buf(str2), min_size); - - return (res > 0 || (res == 0 && size2 < size1)); -} - -bool kstring_gep(TValue str1, TValue str2) -{ - int32_t size1 = kstring_size(str1); - int32_t size2 = kstring_size(str2); - - int32_t min_size = size1 < size2? size1 : size2; - /* memcmp > 0 if str1 has a bigger char in first diff position */ - int res = memcmp(kstring_buf(str1), kstring_buf(str2), min_size); - - return (res > 0 || (res == 0 && size2 <= size1)); -} +bool kstring_lep(TValue str1, TValue str2) { return !kstring_ltp(str2, str1); } +bool kstring_gtp(TValue str1, TValue str2) { return kstring_ltp(str2, str1); } +bool kstring_gep(TValue str1, TValue str2) { return !kstring_ltp(str1, str2); } bool kstring_ci_ltp(TValue str1, TValue str2) { @@ -243,59 +211,17 @@ bool kstring_ci_ltp(TValue str1, TValue str2) bool kstring_ci_lep(TValue str1, TValue str2) { - int32_t size1 = kstring_size(str1); - int32_t size2 = kstring_size(str2); - int32_t min_size = size1 < size2? size1 : size2; - char *buf1 = kstring_buf(str1); - char *buf2 = kstring_buf(str2); - - while(min_size--) { - int diff = (int) tolower(*buf1) - (int) tolower(*buf2); - if (diff > 0) - return false; - else if (diff < 0) - return true; - buf1++, buf2++; - } - return size1 <= size2; + return !kstring_ci_ltp(str2, str1); } bool kstring_ci_gtp(TValue str1, TValue str2) { - int32_t size1 = kstring_size(str1); - int32_t size2 = kstring_size(str2); - int32_t min_size = size1 < size2? size1 : size2; - char *buf1 = kstring_buf(str1); - char *buf2 = kstring_buf(str2); - - while(min_size--) { - int diff = (int) tolower(*buf1) - (int) tolower(*buf2); - if (diff < 0) - return false; - else if (diff > 0) - return true; - buf1++, buf2++; - } - return size1 > size2; + return kstring_ci_ltp(str2, str1); } bool kstring_ci_gep(TValue str1, TValue str2) { - int32_t size1 = kstring_size(str1); - int32_t size2 = kstring_size(str2); - int32_t min_size = size1 < size2? size1 : size2; - char *buf1 = kstring_buf(str1); - char *buf2 = kstring_buf(str2); - - while(min_size--) { - int diff = (int) tolower(*buf1) - (int) tolower(*buf2); - if (diff < 0) - return false; - else if (diff > 0) - return true; - buf1++, buf2++; - } - return size1 >= size2; + return !kstring_ci_ltp(str1, str2); } /* 13.2.5? substring */