Skip to content
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

Closed
1 task done
kensoh opened this issue Mar 16, 2021 · 8 comments
Closed
1 task done
Assignees
Labels

Comments

@kensoh
Copy link
Member

kensoh commented Mar 16, 2021

for example -

  • get_text(source_text, left_marker, right_marker, optional_count)

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"

function get_text(source_text, left_marker, right_marker, optional_count) {
	var pos1, pos2 = 0;
	if(optional_count === undefined || optional_count === 1)
   	{
		pos1 = source_text.indexOf(left_marker);
		pos2 = source_text.indexOf(right_marker);
   	} else {
		var i = 1;
		while(i <= optional_count) {
			pos1 = source_text.indexOf(left_marker, pos1+1);
			pos2 = source_text.indexOf(right_marker, pos2+1);
			i++;
		}
	}
	return source_text.slice(pos1 + left_marker.length, pos2).trim();
}
@kensoh
Copy link
Member Author

kensoh commented May 27, 2021

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

var pos1, pos2 = 0;

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

@kensoh
Copy link
Member Author

kensoh commented May 27, 2021

This line will also have problem with 'marker ... marker ... marker' because first marker will be skipped

pos1 = source_text.indexOf(left_marker, pos1+1);

Changing function to run for first run before starting while loop if needed

@kensoh
Copy link
Member Author

kensoh commented May 27, 2021

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();}

@kensoh kensoh changed the title Helper functions for broader RPA usage such as parsing text - for feedback Helper functions for broader RPA usage such as parsing text added get_text() - done May 27, 2021
@kensoh kensoh changed the title Helper functions for broader RPA usage such as parsing text added get_text() - done Helper functions for RPA usage such as parsing text, added get_text() - done May 27, 2021
@kensoh kensoh changed the title Helper functions for RPA usage such as parsing text, added get_text() - done Helper functions for RPA usage such as parsing text, added get_text() - done May 27, 2021
@kensoh
Copy link
Member Author

kensoh commented May 27, 2021

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.

@kensoh kensoh changed the title Helper functions for RPA usage such as parsing text, added get_text() - done Helper functions for RPA usage such as parsing text, added get_text() - to iterate Jun 2, 2021
@kensoh
Copy link
Member Author

kensoh commented Jun 2, 2021

Reviewing adding another function to remove certain characters in the whole string, \n and \t.

remove_char(get_text(), '\n')

kensoh added a commit that referenced this issue Jun 4, 2021
@kensoh
Copy link
Member Author

kensoh commented Jun 4, 2021

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

a = '1\\2'
echo RESULT - `remove_char(a,'\\')`

do this way

a = '1\\2'
b = remove_char(a,'\\')
echo `b`

@kensoh kensoh changed the title Helper functions for RPA usage such as parsing text, added get_text() - to iterate Helper functions for usage such as parsing text, added get_text() remove_char() - done Jun 4, 2021
@kensoh kensoh changed the title Helper functions for usage such as parsing text, added get_text() remove_char() - done Helper functions for usage such as parsing text, added get_text() remove_chars() - done Jun 13, 2021
@kensoh
Copy link
Member Author

kensoh commented Jun 13, 2021

Above commit rename function to remove_chars() instead to carry the meaning better since it can take multiple characters.

@kensoh
Copy link
Member Author

kensoh commented Jun 18, 2021

Closing issue, change included in latest packaged release - https://github.com/kelaberetiv/TagUI/releases/tag/v6.46.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants