Skip to content
This repository has been archived by the owner on Dec 29, 2018. It is now read-only.

Commit

Permalink
Code update
Browse files Browse the repository at this point in the history
Fixed all my issues, sorry again for all of these commits.
  • Loading branch information
moty66 committed Oct 10, 2013
1 parent 7f27d7c commit 7da83d9
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 38 deletions.
69 changes: 35 additions & 34 deletions string.axi
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ STRING_RETURN_SIZE_LIMIT = 1024 // Maximum string return size
*
* @return An error string.
*/
define_function char[STRING_RETURN_SIZE_LIMIT] string_size_error()
define_function char[0] string_size_error()
{
// handle, alert, ignore etc here
println("'Maximum return size too small in String.axi'")

return 'error'
return ''
}

/**
Expand Down Expand Up @@ -413,9 +413,10 @@ define_function char[10] string_date_invert(char a[])
return "comp[2], '/', comp[1], '/', comp[3]"
}


/**
* Gets the first instance of a string contained within the bounds of two
* substrings
* substrings case sensitive
*
* @param a a string to split
* @param left the character sequence marking the left bound
Expand All @@ -425,52 +426,51 @@ define_function char[10] string_date_invert(char a[])
define_function char[STRING_RETURN_SIZE_LIMIT] string_get_between(char a[],
char left[], char right[])
{
stack_var integer start
stack_var integer end
stack_var integer retlen

start = find_string(a, left, 1)
if (start) {
start = start + length_string(left)
} else {
return ''
}

end = find_string(a, right, start)
if (!end) {
return ''
}

retlen = end - start

if (retlen > STRING_RETURN_SIZE_LIMIT) {
return string_size_error()
}

return mid_string(a, start, retlen)
return string_get_between_ex(a, left, right, true)
}

/**
* Gets the first instance of a string contained within the bounds of two
* substrings, case is not sensitive for left and right
* substrings case insensitive
*
* @param a a string to split, max size is 100 kilobytes
* @param left the character sequence marking the left bound
* @param right the character sequence marking the right bound
* @return a string contained within the boundary sequences
*/
define_function char[STRING_RETURN_SIZE_LIMIT] istring_get_between(char a[],
define_function char[STRING_RETURN_SIZE_LIMIT] string_ci_get_between(char a[],
char left[], char right[])
{
return string_get_between_ex(a, left, right, false)
}

/**
* Gets the first instance of a string contained within the bounds of two
* substrings case sensitive
*
* @param a a string to split
* @param left the character sequence marking the left bound
* @param right the character sequence marking the right bound
* @param cs TRUE for case sensitive search
* @return a string contained within the boundary sequences
*/
define_function char[STRING_RETURN_SIZE_LIMIT] string_get_between_ex(char a[],
char left[], char right[], char cs)
{
stack_var integer start
stack_var integer end
stack_var integer retlen
stack_var char a_copy[STRING_RETURN_SIZE_LIMIT*100];

a_copy = lower_string(a)
start = find_string(a_copy, lower_string(left), 1) + length_string(left)
end = find_string(a_copy, lower_string(right), start)
retlen = end - start

if(true == cs) {
start = find_string(a, left, 1) + length_string(left)
end = find_string(a, right, start)
}
else {
start = find_string(lower_string(a), lower_string(left), 1) + length_string(left)
end = find_string(lower_string(a), lower_string(right), start)
}

retlen = end - start

if (retlen > STRING_RETURN_SIZE_LIMIT) {
return string_size_error()
Expand All @@ -480,6 +480,7 @@ define_function char[STRING_RETURN_SIZE_LIMIT] istring_get_between(char a[],
}



/**
* Returns a copy of a string with the first alpha character capitalized.
* Non alpha characters are not modified. Pass a LOWER_STRING()'d string
Expand Down
8 changes: 4 additions & 4 deletions test/test_string.axi
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ define_function char test_string_get_between(char a[],
return test_end();
}

define_function char test_istring_get_between(char a[],
define_function char test_string_ci_get_between(char a[],
char left[], char right[])
{
stack_var long i

println("'Running istring_get_between(',a, ',',left,', ',right,')'")
println("'Running string_ci_get_between(',a, ',',left,', ',right,')'")
test_timer_start()
for (i = TEST_STRING_ITERATIONS; i; i--) {
istring_get_between(a, left, right)
string_ci_get_between(a, left, right)
}
test_timer_stop(TEST_STRING_ITERATIONS)
return test_end();
Expand All @@ -48,7 +48,7 @@ define_function test_string()
println("'Running string library test suite.'")
println("' '")
test_string_get_between('http://site.com/', 'http://', '/');
test_istring_get_between('http://site.com/', 'HTTP://', '/');
test_string_ci_get_between('http://site.com/', 'HTTP://', '/');
}

#end_if

0 comments on commit 7da83d9

Please sign in to comment.