command /test:
trigger:
set {_p} to parse_links("test&ahttps://docs.skriptlang.org/effects.html どこに&bhttps://docs.skriptlang.org なにが あっても &3http://mirage.com parseします")
send formatted {_p}
function parse_links(str: string) :: string:
set {_start} to 0
set {_end} to 0
set {_last_end} to 0
set {_result} to ""
set {_skipped_text} to ""
while {_start} is not -1:
set {_start} to str_indexof({_str}, "http", {_end})
set {_end} to str_indexof({_str}, " ", {_start}) - 1
if {_start} > {_end}:
set {_end} to length of {_str}
if {_start} * {_end} > 1:
set {_skipped_text} to substring of {_str} from {_last_end} + 1 to {_start} - 1
set {_url} to substring of {_str} from {_start} to {_end}
set {_result} to "%{_result}%%{_skipped_text}%<url:%{_url}%>%{_url}%&r"
set {_last_end} to {_end}
if length of {_result} is 0:
return {_str}
set {_remains} to ""
if {_last_end} < length of {_str}:
set {_remains} to substring of {_str} from {_last_end} + 1 to length of {_str}
set {_result} to "%{_result}%%{_remains}%"
return {_result}
function str_indexof(source: string, find: string, start: number = 1) :: number:
if length of {_source} < {_start}:
return -1
set {_sub} to substring of {_source} from {_start} to length of {_source}
set {_index} to index of {_find} in {_sub}
if {_index} is -1:
return -1
if {_start} > 1:
subtract 1 from {_index}
return {_index} + {_start}