FreeBASIC  0.91.0
strw_comp.c
Go to the documentation of this file.
1 /* wstring compare function */
2 
3 #include "fb.h"
4 
5 FBCALL int fb_WstrCompare( const FB_WCHAR *str1, const FB_WCHAR *str2 )
6 {
7  int res;
8  ssize_t str1_len, str2_len;
9 
10  /* both not null? */
11  if( (str1 != NULL) && (str2 != NULL) )
12  {
13  str1_len = fb_wstr_Len( str1 );
14  str2_len = fb_wstr_Len( str2 );
15 
16  res = fb_wstr_Compare( str1, str2, ((str1_len < str2_len) ? str1_len : str2_len) );
17  if( (res == 0) && (str1_len != str2_len) )
18  res = (( str1_len > str2_len ) ? 1 : -1 );
19 
20  return res;
21  }
22 
23  /* left null? */
24  if( str1 == NULL )
25  {
26  /* right also null? return eq */
27  if( (str2 == NULL) || (fb_wstr_Len( str2 ) == 0) )
28  return 0;
29 
30  /* return lt */
31  return -1;
32  }
33 
34  /* only right is null. is left empty? return eq */
35  if( fb_wstr_Len( str1 ) == 0 )
36  return 0;
37 
38  /* return gt */
39  return 1;
40 }