Skip to content

Commit

Permalink
string module update - string-tools.l1h update
Browse files Browse the repository at this point in the history
  • Loading branch information
koder77 committed Jan 12, 2023
1 parent 4bf4a90 commit b75e936
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 62 deletions.
4 changes: 3 additions & 1 deletion ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ L1VM (2.0.6)
Examples in /lib: train_fann.l1com and train_fann_file.l1com.
FANN module code cleanup. Now uses pointers for the input/output vars.

-- Stefan Pietzonke <jay-t@gmx.net> Sun 1 Jan 2022 04:29 +0100
NEW: string module demo update, string-tools.l1h now uses strimg_left and string_right in string replace function.

-- Stefan Pietzonke <jay-t@gmx.net> Thu 12 Jan 2022 20:33 +0100

L1VM (2.0.5)
Code cleanup.
Expand Down
21 changes: 8 additions & 13 deletions include-lib/string-tools.l1h
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,13 @@
(set int64 1 i~ 0)
(set string 4097 bufstr~ "")
(set string 4097 repstr~ "")
(set string 4097 rightstr~ "")
(set string 2 emptystr~ "")
(set string 2 chstr~ "")
(set int64 1 string_len~ 0)
(set int64 1 stringsearch_len~ 0)
(set int64 1 left_string~ 0)
(set int64 1 right_string~ 0)
(stringretaddr~ stringreplaceaddr~ stringsearchaddr~ stringaddr~ stpop)
(bufstr~ stringaddr~ :string_copy !)
(repstr~ emptystr~ :string_copy !)
Expand All @@ -91,24 +94,16 @@
// found search string in string, replace
(((pos~ zero~ !=) f~ =) f~ if)
// leading chars before replace string, copy
(zero~ i~ =)
(for-loop)
(((i~ pos~ <) f~ =) f~ for)
(bufstr~ chstr~ i~ :string_mid !)
(repstr~ chstr~ :string_cat !)
((i~ one~ +) i~ =)
(next)
(pos~ left_string~ =)
(bufstr~ repstr~ left_string~ :string_left !)
(endif)
(repstr~ stringreplaceaddr~ :string_cat !)
(((pos~ string_len~ <) f~ =) f~ if)
// copy chars after replace string
((pos~ stringsearch_len~ +) i~ =)
(for-loop)
(((i~ string_len~ <) f~ =) f~ for)
(bufstr~ chstr~ i~ :string_mid !)
(repstr~ chstr~ :string_cat !)
((i~ one~ +) i~ =)
(next)
((string_len~ i~ -) right_string~ =)
(bufstr~ rightstr~ right_string~ :string_right !)
(repstr~ rightstr~ :string_cat !)
(endif)
// copy repstr~ to bufstr~ for next loop
(bufstr~ repstr~ :string_copy !)
Expand Down
95 changes: 47 additions & 48 deletions lib/string.l1com
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// now with string array demo
#include <intr.l1h>
(main func)
(set int64 1 zero 0)
(set int64 1 one 1)
Expand Down Expand Up @@ -33,81 +34,79 @@
(set int64 1 maxlen 255)
(set int64 1 ret 0)
(set int64 1 f 0)
(set string s rep_in_str "Hello 123!")
(set string 4097 rep_out_str "")
(set string s search_rep_str "123")
(set string s rep_str "world")
(zero :string_init call)
(loadreg)
// copy hellostr to array
(hellostraddr arraystraddr zero string_len array_size :string_to_array call)
(loadreg)
// copy worldstr to array
(worldstraddr arraystraddr one string_len array_size :string_to_array call)
(loadreg)
// get strings from array
(arraystraddr hellostr2addr zero string_len array_size :array_to_string call)
(loadreg)
(arraystraddr worldstr2addr one string_len array_size :array_to_string call)
(loadreg)
(6 hellostr2 0 0 intr0)
(6 worldstr2 0 0 intr0)
(7 0 0 0 intr0)
(7 0 0 0 intr0)
print_s (hellostr2)
print_n
print_s (worldstr2)
print_n
print_n
(hellostraddr worldstraddr :string_cat call)
(loadreg)
(6 hellostr 0 0 intr0)
(7 0 0 0 intr0)
print_s (hellostr)
print_n
(hellostraddr :string_len call)
(slen stpopi)
(loadreg)
(4 slen 0 0 intr0)
(7 0 0 0 intr0)
print_i (slen)
print_n
(hellostraddr hellostr2addr hello_len :string_left call)
(loadreg)
(6 hellostr2 0 0 intr0)
(7 0 0 0 intr0)
print_s (hellostr2)
print_n
(hellostraddr worldstr2addr world_len :string_right call)
(loadreg)
(6 worldstr2 0 0 intr0)
(7 0 0 0 intr0)
print_s (worldstr2)
print_n
(slen bufstr buflen :string_int64tostring call)
(loadreg)
(6 bufstr 0 0 intr0)
(7 0 0 0 intr0)
print_s (bufstr)
print_n
(bytenum bufstr buflen :string_bytetohexstring call)
(loadreg)
(6 bufstr 0 0 intr0)
(7 0 0 0 intr0)
print_s (bufstr)
print_n
// get char at positon mid_pos in hellostr
(hellostraddr bufstr mid_pos :string_mid call)
(loadreg)
(6 bufstr 0 0 intr0)
(7 0 0 0 intr0)
print_s (bufstr)
print_n
(dotstraddr hellostraddr dot_pos :string_to_string call)
(loadreg)
(6 hellostr 0 0 intr0)
(7 0 0 0 intr0)
print_s (hellostr)
print_n
// check regex function:
(regexsrcstraddr regexstr :string_regex call)
(ret stpopi)
(((ret zero ==) f =) f if+)
(6 regex_foundstr 0 0 intr0)
(7 0 0 0 intr0)
print_s (regex_foundstr)
print_n
(else)
(6 regex_notfoundstr 0 0 intr0)
(7 0 0 0 intr0)
print_s (regex_notfoundstr)
print_n
(endif)

// JSON parse function
(6 json_infostr 0 0 intr0)
(7 0 0 0 intr0)
(6 jsonstr 0 0 intr0)
(7 0 0 0 intr0)
print_s (json_infostr)
print_n
print_s (jsonstr)
print_n
(jsonstr keystr valuestr maxlen :string_parse_json !)
(ret stpop)
(4 ret 0 0 intr0)
(7 0 0 0 intr0)
(6 keystr 0 0 intr0)
(7 0 0 0 intr0)
(6 valuestr 0 0 intr0)
(7 0 0 0 intr0)
(255 0 0 0 intr0)
print_i (ret)
print_n
print_s (keystr)
print_n
print_s (valuestr)
print_n

// replace string
(rep_in_str search_rep_str rep_str rep_out_str :string_replace !)
print_s (rep_out_str)
print_n
exit (zero)
(funcend)
#include <string.l1h>
#include <string-tools.l1h>

0 comments on commit b75e936

Please sign in to comment.