Home >

Requirements

Download

Version 1.3.1 -- 2017-05-09

Old Versions

Dependencies

XText

XText is a wrapper object of AppleScript's text object. XText provides object oriented interface to manipulate text and some advanced features.

The parent of instances of XText is AppleScript's text object. Therefore ...

  • Properties of AppleScript's text can be obtained form a XText instance in same way to normal AppleScript's text object (string and Unicode text).
  • An instance of XText is immutable like string or Unicode class object.

Using Class Methods

use XText : script "XText"

tell XText
store_delimiters() -- storing AppleScript's text item delimiters

log (replace for "this is a pen" from "pen" by "flower")
-- result : "this is a flower"

set a_list to split("this is a pen", space)
log a_list -- result : {"this", "is", "a", "pen"}
log join_list(a_list, "-") -- result : "this-is-a-pen"

log strip(" this is a pen ") -- ressult : "this is a pen"
log strip_beginning(" this is a pen ")
-- result : {" ", "this is a pen "}
log strip_endding(" this is a pen ")
-- result : {" "," this is a pen"}

log formatted_text("$1 is $2.", {"XText", "useful"})
-- result : "XText is useful."

restore_delimiters() -- restoring AppleScript's text item delimiters
end tell

Using Instance Methods

use XText : script "XText"

(* Make a XText Instance *)
set a_text to XText's make_with("this is a pen")

(*Replacing *)
log a_text's replace("pen", "flower")
-- result : [XText] this is a flower

(* Appending and Prepennding *)
set spaced_text to a_text's prepend(return & tab)
set spaced_text to spaced_text's push(space)

log spaced_text
(*[XText]
this is a pen *)

(* Stripping *)
log spaced_text's strip() -- result : [XText] this is a pen

set a_result to spaced_text's strip_beginning()
log item 1 of a_result
(*
*)
log item 2 of a_result
-- result : [XText] this is a pen

set a_result to spaced_text's strip_endding()
log item 1 of a_result
(* *)
log item 2 of a_result
(*[XText]
this is a pen*)

(*Check Contents *)
log a_text's starts_with("this") -- (*true*)
log a_text's ends_with("this") -- (*false*)
log a_text's include("is") -- (*true*)
log a_text's offset_of("is") -- (*3*)

(* Make a list with splitting *)
log a_text's as_xlist_with(space)
(*[XList]
1 this
2 is
3 a
4 pen*)

log a_text's as_list_with(space) -- result : {"this", "is", "a", "pen"}

(* Obtain a part of text *)
log a_text's character_at(1) -- result : [XText] t
log a_text's word_at(1) -- result : [XText] this
log a_text's paragraph_at(1) -- result : [XText] this is a pen

(* Obtain of AppleScript's text properties *)
log character 1 of a_text -- result : "t"
log word 1 of a_text -- result : "this"
log length of a_text -- result : 13

(* Obtain content as AppleScript's text *)
a_text's as_unicode()
a_text's as_string()

History

  • 1.3.1 -- 2017-05-08
    • Fixed links to XList in the help book.
  • 1.3 -- 2016-10-19
    • Enabled to work with AppleScript Libraries.
    • Remove dependency on ModuleLoader.
    • OS X 10.9 or later is required.
  • 1.2.2 -- 2015-09-04
    • character_at returns a new instance of XText instead of AppleScript text class object.
  • 1.2.1 -- 2012-04-22
    • The second argument can accept a text.
    • BEL (character id 7) has been added into removed characters by strip, strip_beginning and strip_endding.
    • Update Help.
      • Fixed : "Edit Link" and handler's copy link does not work in Mac OS X 10.6.
  • 1.2 -- 2010-02-02
    • ModuleLoader 2.1 or later is requied to load "XText"
    • Removed dependency on "ShowHelpBook".
    • "join" was renamed to "join_list".
  • 1.1 -- 2008-03-19
    • Remove dependency on StringEngine
    • Add meny class methods
    • Add Japanese documents
  • 1.0 -- 2007.07.10
    • First Release