50 #define y_get_int_from_char(c) (isdigit(c) ? c - ‘0’: 0) 69 #define y_int_strlen(number) (number?(int)floor(log10(abs(number)))+(number<0?2:1):1) 91 lr_eval_string_ext(source,
strlen(source), &buffer, &size, 0, 0, -1);
93 lr_save_var(buffer, size, 0, dest_param);
94 lr_eval_string_ext_free(&buffer);
119 lr_error_message(
"Nonexistant parameter %s passed to y_uppercase_parameter(): Aborting.", param_name);
123 lr_save_string(result, param_name);
144 void y_substr(
const char *original_parameter,
const char *result_parameter,
const char *left,
const char *right)
150 lr_error_message(
"y_substr(): Error: Parameter %s does not exist!", original_parameter);
157 if (p1) str = p1 +
strlen(left);
165 lr_param_sprintf(result_parameter,
"%.*s", p1 - str, str);
169 lr_save_string(str, result_parameter);
188 void y_left(
const char *original_parameter,
const char *search,
const char *result_parameter )
191 if( original == NULL )
193 lr_error_message(
"y_left(): Error: Parameter %s does not exist!", original_parameter);
196 else if( search == NULL ||
strlen(search) == 0 )
198 lr_save_string(original, result_parameter);
199 lr_log_message(
"Warning: Empty search parameter passed to y_left()");
205 char *posPtr = (
char *)
strstr(original, search);
206 int pos = (int)(posPtr - original);
211 lr_save_string(original, result_parameter);
219 lr_save_string(buffer, result_parameter);
240 void y_right(
const char *original_parameter,
const char *search,
const char *result_parameter)
243 if( original == NULL )
245 lr_error_message(
"y_right(): Error: Parameter %s does not exist!", original_parameter);
248 else if( search == NULL ||
strlen(search) == 0 )
250 lr_save_string(original, result_parameter);
251 lr_log_message(
"Warning: Empty search parameter passed to y_right()");
256 char* posPtr = (
char *)
strstr(original, search);
262 lr_save_string(original, result_parameter);
266 posPtr = posPtr +
strlen(search);
267 lr_save_string(posPtr, result_parameter);
290 void y_last_right(
const char *original_parameter,
const char *search,
const char *result_parameter)
295 lr_error_message(
"y_last_right(): Error: Parameter %s does not exist!", original_parameter);
298 else if( search == NULL ||
strlen(search) == 0 )
300 lr_save_string(result, result_parameter);
301 lr_log_message(
"Warning: Empty search parameter passed to y_last_right()");
310 posPtr = (
char *)
strstr(result, search);
317 lr_save_string(result, result_parameter);
321 result = posPtr +
strlen(search);
341 void y_split_str(
const char *original,
const char *separator,
char *left,
char *right)
344 char *posPtr = (
char *)
strstr(original, separator);
345 int pos = (int)(posPtr - original);;
363 char *start = posPtr +
strlen(separator);
389 void y_split(
const char *originalParameter,
const char *separator,
const char *leftParameter,
const char *rightParameter)
394 if( len <
strlen(separator) )
398 lr_save_string(originalParameter, leftParameter);
399 lr_save_string(
"", rightParameter);
425 lr_save_string(left, leftParameter);
427 lr_save_string(right, rightParameter);
465 character = result[i];
466 while( (character ==
' ') || (character ==
'\r') || (character ==
'\n') || (character ==
'\t') )
468 character = result[++i];
476 character = result[i];
478 ( (character ==
' ' ) ||
479 (character ==
'\r') ||
480 (character ==
'\n') ||
481 (character ==
'\t') ) )
483 character = result[--i];
487 lr_save_string(result, parameter);
508 void y_replace(
const char *parameter,
const char *search,
const char *replace )
510 int slen, rlen, plen;
520 if ((search == NULL) || (
strlen(search) <1))
522 if (!search || !replace)
return;
523 if (!
strcmp(search, replace))
return;
536 size_t size = plen + ((rlen-slen) * limit);
538 snprintf( buffer, size,
"%s",
string );
546 last = buffer +
strlen(buffer) +1;
549 while (c = (
char*)
strstr(c, search))
558 lr_log_message(
"Unable to handle more than %d search-and-replaces, apologies for the inconvenience.", limit);
563 memmove (c+rlen , cend, last-cend);
565 last = last - slen + rlen;
570 lr_save_string(buffer, parameter);
602 if(!removeMe || !*removeMe)
608 removePtr = parameter;
609 remlen =
strlen(removeMe);
612 while ( removePtr = (
char *)
strstr( removePtr, removeMe ) )
616 char* origin = removePtr + remlen;
621 lr_save_string( parameter, paramName );
639 lr_generate_uuid_on_buf(buf);
640 lr_save_var(buf, 22, 0, param);
679 int minWordLength,
int maxWordLength,
char *characterSet)
689 charSetSize=
strlen(characterSet);
695 if( minimumLength < 0 ) {
696 lr_error_message(
"minimumLength less than 0 (%d)", minimumLength );
698 else if( maximumLength < 1 ) {
699 lr_error_message(
"maximumLength less than 1 (%d)", maximumLength );
701 else if( maximumLength > (1024 * 1024) ) {
702 lr_error_message(
"maximumLength too big (%d)", maximumLength );
704 else if( maximumLength < minimumLength ) {
705 lr_error_message(
"minimumLength (%d) bigger than maximumLength (%d)", minimumLength, maximumLength );
707 else if(maximumLength > minimumLength) {
710 lr_log_message(
"Max: %d", max);
712 else if(maximumLength == minimumLength) {
717 lr_error_message(
"This can never happen. If we reach this point it's a bug.");
723 lr_set_transaction_status(LR_FAIL);
724 lr_exit(LR_EXIT_ITERATION_AND_CONTINUE, LR_FAIL);
731 while( length < max )
735 if( maxWordLength == 0 )
737 lettersInWord = maximumLength;
742 if( lettersInWord < 0 )
744 lr_error_message(
"y_rand_between() returned an errorcode (%d)", lettersInWord );
745 lr_set_transaction_status(LR_FAIL);
746 lr_exit(LR_EXIT_ITERATION_AND_CONTINUE, LR_FAIL);
750 while( lettersInWord-- && (length < (max)) )
752 randomNumber = (char) (
y_rand() % charSetSize);
753 buffer[length++] = characterSet[randomNumber];
756 if( maxWordLength != 0 )
758 if( length < max -1 )
760 buffer[length++] =
' ';
766 lr_save_string(buffer, parameter);
787 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
871 unsigned long result_size;
872 size_t param_eval_size =
strlen(param_name) +3;
873 char* param_eval_string =
y_mem_alloc(param_eval_size);
878 snprintf( param_eval_string, param_eval_size,
"{%s}", param_name );
879 lr_eval_string_ext(param_eval_string, param_eval_size-1, &result, &result_size, 0, 0, -1);
880 if(
strcmp(param_eval_string, result) == 0 )
882 lr_error_message(
"y_get_cleansed_parameter: Parameter %s does not exist.", param_name);
885 free(param_eval_string);
890 for(ptr = result; result_size--; ptr++)
891 if (*ptr == 0) *ptr = replacement;
928 if( param_name &&
strlen(param_name) )
931 lr_save_string(result, param_name);
932 lr_eval_string_ext_free(&result);
936 lr_error_message(
"Empty or NULL parameter name passed to y_cleanse_parameter_ext(): %s", param_name);
963 #endif // _Y_STRING_C_ char * strupr(char *string)
Documented at http://www.qnx.com/developers/docs/6.5.0/topic/com.qnx.doc.neutrino_lib_ref/s/strupr.html .
void y_left(const char *original_parameter, const char *search, const char *result_parameter)
Split a string into 2 parts using the search string. Save the left part into the result parameter...
void y_cleanse_parameter(const char *param_name)
Clean a parameter by replacing any embedded NULL (null) characters with a space. This is identical to...
void y_chop(const char *parameter)
Remove leading and trailing whitespace from a parameter.
char * strstr(const char *string1, const char *string2)
Documented at http://www.cplusplus.com/reference/cstring/strstr/.
char * y_mem_alloc(size_t size)
Ylib wrapper for malloc()
Contains core ylib support functions needed for the functioning of the library.
void y_remove_string_from_parameter(const char *paramName, const char *removeMe)
Remove all occurrences of a specified text from a parameter.
int strcmp(const char *string1, const char *string2)
Documented at http://www.cplusplus.com/reference/cstring/strcmp/.
void y_substr(const char *original_parameter, const char *result_parameter, const char *left, const char *right)
Save a substring of a parameter into a new parameter. Search for a specific substring inside a parame...
void y_random_string_buffer(const char *parameter, int minimumLength, int maximumLength)
Returns a random string with (pseudo) words created from a given string of characters.
void * memmove(void *dest, const void *src, size_t n)
Documented at http://www.cplusplus.com/reference/cstring/memmove/.
void y_replace(const char *parameter, const char *search, const char *replace)
Search and replace inside a parameter. This replaces the content of the originally passed-in paramete...
char * y_get_cleansed_parameter(const char *param_name, char replacement)
Get the content of a parameter without embedded null bytes (\0 characters) from the named parameter...
char * y_get_parameter_eval_string(const char *param_name)
Obtain the string required to fetch the contents of a parameter through lr_eval_string().
void y_right(const char *original_parameter, const char *search, const char *result_parameter)
Split a string into 2 parts using the search string. Save the right part into the result parameter...
void y_random_number_buffer(const char *parameter, int minimumLength, int maximumLength)
Returns a random string of numbers with a given minimum and maximum length.
void y_split(const char *originalParameter, const char *separator, const char *leftParameter, const char *rightParameter)
Split a parameter in two based on a seperating string. If the seperator is not found in the original ...
void y_random_string_buffer_core(const char *parameter, int minimumLength, int maximumLength, int minWordLength, int maxWordLength, char *characterSet)
Generates a random string with (pseudo) words created from a given string of characters.
char * y_strdup(char *source)
Copy a string into a malloc'd piece of memory using strdup(), and lr_abort() if the allocation fails...
size_t strlen(const char *string)
Documented at http://www.cplusplus.com/reference/cstring/strlen/.
void y_last_right(const char *original_parameter, const char *search, const char *result_parameter)
Split a string into 2 parts using the search string. Save the rightmost part into the result paramete...
void y_cleanse_parameter_ext(const char *param_name, char replacement)
Clean a parameter by replacing any embedded NULL (null) characters with a replacement character...
int snprintf(char *buffer, size_t n, const char *format_string,...)
Documented at http://www.cplusplus.com/reference/cstdio/snprintf/. This function was introduced by t...
long y_rand(void)
Generate a random (integer) number between 0 and Y_RAND_MAX (30 bit maxint).
void y_uppercase_parameter(const char *param_name)
Convert the content of a parameter to UPPERCASE.
char * y_get_parameter(const char *param_name)
Get the content of a parameter and return it as a char *.
void y_random_string_buffer_hex(const char *parameter, int minimumLength, int maximumLength)
Generates a random string with a hexadecimal number, of a given minimum and maximum length...
void y_copy_param(char *source_param, char *dest_param)
Copy a parameter to a new name. This is a semi-efficiënt parameter copy using lr_eval_string_ext(), with appropriate freeing of memory.
char * y_get_parameter_or_null(const char *param_name)
Get the content of a parameter and return it as a char *, or return NULL if it wasn't set...
int y_rand_between(int lowerbound, int upperbound)
Create a random number between two boundaries. (the boundaries are included!)
char * strncpy(char *destination, const char *source, size_t num)
Documented at http://www.cplusplus.com/reference/cstring/strncpy/.
void y_split_str(const char *original, const char *separator, char *left, char *right)
Split a string into 2 parts based on a search string.
void y_random_string_buffer_curses(const char *parameter, int minimumLength, int maximumLength)
Returns a string containing only the "shift-1...shift 9 characters (on a US-keyboard).
void free(void *mem_address)
Documented at http://www.cplusplus.com/reference/cstdlib/free/.
void y_param_unique(char *param)
Create a unique parameter.