|
4 | 4 |
|
5 | 5 | FBCALL FB_WCHAR *fb_WstrTrimEx ( const FB_WCHAR *src, const FB_WCHAR *pattern ) |
6 | 6 | { |
7 | | - FB_WCHAR *dst; |
| 7 | + FB_WCHAR *dst; |
8 | 8 | ssize_t len; |
9 | | - const FB_WCHAR *p = NULL; |
| 9 | + const FB_WCHAR *p = src; |
10 | 10 |
|
11 | | - if( src == NULL ) { |
12 | | - return NULL; |
13 | | - } |
| 11 | + if( src == NULL ) { |
| 12 | + return NULL; |
| 13 | + } |
14 | 14 |
|
15 | | - { |
16 | | - ssize_t len_pattern = fb_wstr_Len( pattern ); |
17 | | - len = fb_wstr_Len( src ); |
18 | | - if( len >= len_pattern ) { |
19 | | - if( len_pattern==1 ) { |
20 | | - p = fb_wstr_SkipChar( src, |
21 | | - len, |
22 | | - *pattern ); |
23 | | - len = len - (ssize_t)(p - src); |
| 15 | + { |
| 16 | + ssize_t len_pattern = fb_wstr_Len( pattern ); |
| 17 | + len = fb_wstr_Len( src ); |
| 18 | + if( len >= len_pattern ) { |
| 19 | + if( len_pattern==1 ) { |
| 20 | + p = fb_wstr_SkipChar( src, |
| 21 | + len, |
| 22 | + *pattern ); |
| 23 | + len -= fb_wstr_CalcDiff( src, p ); |
24 | 24 |
|
25 | | - } else if( len_pattern != 0 ) { |
26 | | - p = src; |
27 | | - while (len >= len_pattern ) { |
28 | | - if( fb_wstr_Compare( p, pattern, len_pattern )!=0 ) |
29 | | - break; |
30 | | - p += len_pattern; |
31 | | - len -= len_pattern; |
32 | | - } |
33 | | - } |
34 | | - } |
35 | | - if( len >= len_pattern ) { |
36 | | - if( len_pattern==1 ) { |
37 | | - const FB_WCHAR *p_tmp = |
38 | | - fb_wstr_SkipCharRev( p, |
39 | | - len, |
40 | | - *pattern ); |
41 | | - len = (ssize_t)(p_tmp - p) + 1; |
| 25 | + } else if( len_pattern != 0 ) { |
| 26 | + p = src; |
| 27 | + while (len >= len_pattern ) { |
| 28 | + if( fb_wstr_Compare( p, pattern, len_pattern )!=0 ) |
| 29 | + break; |
| 30 | + p += len_pattern; |
| 31 | + len -= len_pattern; |
| 32 | + } |
| 33 | + } |
| 34 | + } |
| 35 | + if( len >= len_pattern ) { |
| 36 | + if( len_pattern==1 ) { |
| 37 | + const FB_WCHAR *p_tmp = |
| 38 | + fb_wstr_SkipCharRev( p, |
| 39 | + len, |
| 40 | + *pattern ); |
| 41 | + len = fb_wstr_CalcDiff( p, p_tmp ); |
42 | 42 |
|
43 | | - } else if( len_pattern != 0 ) { |
44 | | - ssize_t test_index = len - len_pattern; |
45 | | - while (len >= len_pattern ) { |
46 | | - if( fb_wstr_Compare( p + test_index, |
47 | | - pattern, |
48 | | - len_pattern )!=0 ) |
49 | | - break; |
50 | | - test_index -= len_pattern; |
51 | | - } |
52 | | - len = test_index + len_pattern; |
| 43 | + } else if( len_pattern != 0 ) { |
| 44 | + ssize_t test_index = len - len_pattern; |
| 45 | + while (len >= len_pattern ) { |
| 46 | + if( fb_wstr_Compare( p + test_index, |
| 47 | + pattern, |
| 48 | + len_pattern )!=0 ) |
| 49 | + break; |
| 50 | + test_index -= len_pattern; |
| 51 | + } |
| 52 | + len = test_index + len_pattern; |
53 | 53 |
|
54 | | - } |
55 | | - } |
| 54 | + } |
| 55 | + } |
56 | 56 | } |
57 | 57 |
|
58 | 58 | if( len > 0 ) |
59 | 59 | { |
60 | 60 | /* alloc temp string */ |
61 | | - dst = fb_wstr_AllocTemp( len ); |
| 61 | + dst = fb_wstr_AllocTemp( len ); |
62 | 62 | if( dst != NULL ) |
63 | 63 | { |
64 | 64 | /* simple copy */ |
65 | 65 | fb_wstr_Copy( dst, p, len ); |
66 | 66 | } |
67 | 67 | else |
68 | 68 | dst = NULL; |
69 | | - } |
| 69 | + } |
70 | 70 | else |
71 | 71 | dst = NULL; |
72 | 72 |
|
|
0 commit comments