-
Notifications
You must be signed in to change notification settings - Fork 585
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Helper functions for usage such as parsing text, added get_text() remove_chars() - done #972
Comments
Fyi @ruthtxh not sure of latest JS, but for TagUI's JS, below will make pos1 have no value instead of 0. Now making some change and adding to tagui_header.js
another change is the pos2 the search should begin after left marker. otherwise if a right marker happens before left marker will give error results |
This line will also have problem with
Changing function to run for first run before starting while loop if needed |
Fyi @ruthtxh below is updated version. Other than above, also added checks for valid input parameters, and to return '' when any time a match is not found. Also combined lines to reduce from 15 lines to 7 lines. For performance improvement because tagui_header.js will be loaded line by line during generation of the JavaScript code. To be reviewed whether that part can be improved or worth improving by loading and writing tagui_header.js all at one go. // retrieve text between 2 provided anchors in given text content
function get_text(source_text, left_marker, right_marker, optional_count) {
if (!source_text || !left_marker || !right_marker) return '';
var left_position = source_text.indexOf(left_marker); if (left_position == -1) return '';
var right_position = source_text.indexOf(right_marker, left_position+1); if (right_position == -1) return '';
if (optional_count > 1) {var occurrence_count = 2; while(occurrence_count <= optional_count) {occurrence_count++;
left_position = source_text.indexOf(left_marker, right_position+1); if (left_position == -1) return '';
right_position = source_text.indexOf(right_marker, left_position+1); if (right_position == -1) return '';}}
return source_text.slice(left_position + left_marker.length, right_position).trim();} |
Above commit implements get_text(). Users can download the latest copy of TagUI with this and unzip to overwrite your existing installation (please drag the folders under tagui\src to overwrite your existing installation) - https://github.com/kelaberetiv/TagUI/archive/master.zip In the next release, this will become part of the packaged zip files. |
Reviewing adding another function to remove certain characters in the whole string,
|
Above commit implements get_text() and remove_char(). Users can download the latest copy of TagUI with this and unzip to overwrite your existing installation (please drag the folders under tagui\src to overwrite your existing installation) - https://github.com/kelaberetiv/TagUI/archive/master.zip In the next release, this will become part of the packaged zip files. PS - note there is issue removing backslash when combined with echo statement, due to language parsing limitations issue
do this way
|
Above commit rename function to remove_chars() instead to carry the meaning better since it can take multiple characters. |
Closing issue, change included in latest packaged release - https://github.com/kelaberetiv/TagUI/releases/tag/v6.46.0 |
for example -
examples of usage:
source_text = "welcome to the home... welcome to my home... welcome to our home"
without optional_count, function returns first occurrence of text in between "welcome and "home":
get_text(source_text, 'welcome', 'home')
returns "to the"without optional_count, function returns n occurrence of text in between "welcome and "home":
get_text(source_text, 'welcome', 'home', 2)
returns "to my", which is the 2nd occurrence of text in between "welcome" and "home"The text was updated successfully, but these errors were encountered: