Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rtlib: split LEFT() and LEFTSELF() to separate files
- Loading branch information
Showing
2 changed files
with
43 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* leftself statement */ | ||
|
||
#include "fb.h" | ||
|
||
/* | ||
Special case of a = left( a, n ) | ||
The string 'a' is not reallocated, only the string length field is adjusted | ||
and a NUL terminator written. fbc does not optimize for this so to use, | ||
it must be a direct call by the user. Careful, due the function declaration, it | ||
does not check for fb_LEFTSELF( "literal", n ) so if src is a temporary, | ||
it just gets deleted. | ||
*/ | ||
FBCALL void fb_LEFTSELF( FBSTRING *src, ssize_t chars ) | ||
{ | ||
ssize_t src_len; | ||
|
||
if( src == NULL ) | ||
return; | ||
|
||
FB_STRLOCK(); | ||
|
||
src_len = FB_STRSIZE( src ); | ||
if( (src->data != NULL) && (chars >= 0) && (src_len >= 0) ) | ||
{ | ||
if( chars > src_len ) | ||
{ | ||
fb_hStrSetLength( src, src_len ); | ||
/* add a NUL character */ | ||
src->data[src_len] = '\0'; | ||
} | ||
else | ||
{ | ||
fb_hStrSetLength( src, chars ); | ||
/* add a NUL character */ | ||
src->data[chars] = '\0'; | ||
} | ||
} | ||
|
||
/* del if temp */ | ||
fb_hStrDelTemp_NoLock( src ); | ||
|
||
FB_STRUNLOCK(); | ||
} |