Lisp strings in Creo Elements/Direct Modeling support the full range of Unicode characters. More precisely, the encoding used internally for strings and characters is UTF-16 (without Unicode surrogate support) Characters from any language covered by the Unicode standard can be used and even mixed within a single string. All the standard Common Lisp string handling functionality is available to process strings. Furthermore, there are APIs to convert strings and files between various encodings.
Versions of Creo Elements/Direct Modeling prior to OneSpace Modeling 2007 did not have Unicode support yet. In those versions, there was a distinction between extended strings which could contain multibyte characters as they are required particularly for East Asian languages, and standard Lisp strings, where each character was represented by a single byte. Extended strings could not be manipulated using the standard Lisp string functions. If you tried, usually you got an error message like this:
LISP error: "Foo" is not of type Lisp::SEQUENCE.
For full compatibility with all string types, both standard and extended, we recommended to use only the string functions described in this document. Those string functions were explicitly written to process both standard and extended strings.
With OneSpace Modeling 2007, the distinction between standard and extended strings disappears, and the restrictions for string handling have been lifted. Hence, you can now use any Common Lisp string function on any Creo Elements/Direct Modeling string! For documentation on Common Lisp, please consult the Common Lisp HyperSpec or a Common Lisp reference book, in particular the chapters on arrays, sequences and strings.
If your string processing code must run in versions before OneSpace Modeling 2007 and later, we recommend to use only the string functions documented here to ensure full compatiblity with older versions.
For background information on Unicode and advanced string processing, please consult the Unicode concepts documentation.
In the function descriptions in this document, a type specification of {STRING} refers to a string of any type (standard or extended).
(format destination control-string [arguments])
Guy L. Steele, Jr.
Common Lisp - The Language - Second Edition
Digital Press
ISBN 1-55558-041-6
(setq part-height 33.75) (setq a-string (format nil "Part ~S has a height of ~A~%" (sd-inq-obj-basename (sd-inq-curr-part)) part-height))
(length sequence)
Guy L. Steele, Jr.
Common Lisp - The Language - Second Edition
Digital Press
ISBN 1-55558-041-6
(display (length "This is a string"))
(OPEN filespec &key direction element-type if-exists if-does-not-exist external-format)
So for example, if you specify :utf-8 as the external format for a new file which is to be written, any data that you write to the file stream will be automatically converted into UTF-8.
There are two groups of supported encoding specifications, explicit and symbolic. Explicit specifications denote the actual encoding to be used, while symbolic specifications delegate the decision about the required encoding to Creo Elements/Direct Modeling.
The currently supported explicit encoding specifications are:
The currently supported symbolic encoding specifications are:
Most useful for communicating with older versions of Creo Elements/Direct Modeling or Creo Elements/Direct Drafting. This is also the implicit default encoding if you don't specify an :external-format explicitly.
:system - this is the encoding which the operating system chooses by default for non-Unicode applications. On Western European versions of Windows, this is an encoding known as "codepage 1252" (sometimes also referred to as "ANSI" or "ISO8859-1"). On Japanese systems, the default Windows encoding is Shift-JIS (or, more precisely, codepage 932).
Most useful when communicating with external non-Unicode components and applications.
:locale - Like :system, but the choice of encoding depends on the language in which Creo Elements/Direct Modeling currently runs rather than the operating system's language. When running Creo Elements/Direct Modeling in a Western European language or in English, :locale evaluates to "codepage 1252" (which is mostly equivalent to ISO8859-1, see above), even if Creo Elements/Direct Modeling runs on a Japanese or Chinese operating system.
All the above symbolic encodings have in common that they do not cover the full range of Unicode characters, so when writing data from Creo Elements/Direct Modeling to a file, some data may be lost during the conversion.
The following table illustrates the differences between the above symbolic encodings:
Symbolic encoding | Windows: English Creo Elements/Direct Modeling: English |
Windows: English Creo Elements/Direct Modeling: Japanese |
Windows: Japanese Creo Elements/Direct Modeling: English |
Windows: Japanese Creo Elements/Direct Modeling: Japanese |
---|---|---|---|---|
:legacy | HP-Roman8 | Shift-JIS (codepage 932) | HP-Roman8 | Shift-JIS (CP932) |
:locale | ISO8859-1 (CP1252) | Shift-JIS (CP932) | ISO8859-1 (CP1252) | Shift-JIS (CP932) |
:system | ISO8859-1 (CP1252) | ISO8859-1 (CP1252) | Shift-JIS (CP932) | Shift-JIS (CP932) |
The with-open-file macro also accepts an :external-format specification. For a full description of (open) and (with-open-file), consult the Common Lisp HyperSpec or any Common Lisp reference book, such as:
Guy L. Steele, Jr.
Common Lisp - The Language - Second Edition
Digital Press
ISBN 1-55558-041-6
(let ((out (open "foobar_utf16.txt" :direction :output :if-exists :supersede :if-does-not-exist :create :external-format :utf-16))) (print "foobar" out) (close out)) (with-open-file (in "foobar_utf8.txt" :direction :input :external-format :utf-8) (display (read-line in nil nil)))
(load filename)
Starting with OneSpace Modeling 2007, (load) supports the :external-format keyword which can be used to specify the encoding of the file which is to be loaded. For a list of encodings, see above. If no encoding is specified, (load) will try to detect the encoding of the file automatically:
For a full description, consult the Common Lisp HyperSpec or any Common Lisp reference book, such as:
Guy L. Steele, Jr.
Common Lisp - The Language - Second Edition
Digital Press
ISBN 1-55558-041-6
(load "foo.lsp" :external-format :iso8859-1)
(sd-string-p value)
(sd-string-p "Foo")
(sd-string= string-1 string-2) (sd-string< string-1 string-2) (sd-string> string-1 string-2) (sd-string<= string-1 string-2) (sd-string>= string-1 string-2) (sd-string/= string-1 string-2)
(sd-string= "Foo" "foo") => NIL (sd-string< "Foo" "foo") => 0 (sd-string< "Part" "Party") => 4 (sd-string> "Foo" "foo") => NIL (sd-string<= "A" "B") => 0 (sd-string<= "A" "Aa") => 1
(sd-string-upcase string) (sd-string-downcase string)
(sd-string-upcase "HellO") => "HELLO" (sd-string-downcase "Part1") => "part1"
(sd-string-trim string)
(sd-string-trim " Part 1 ") => "Part 1"
(sd-string-split string delimiter)
(sd-string-split "A-long-string" "-") => ("A" "long" "string")
(sd-string-replace string pattern replacement)
(sd-string-replace "/asmb1/asmb2/p1" "asmb" "a") => "/a1/a2/p1"
(sd-num-to-string number [digits])
(sd-num-to-string 57.0) => "57" (sd-num-to-string 52.1 0) => "52.1" (sd-num-to-string 0.1234567) => "0.123457" (sd-num-to-string 12345678901234567) => "1.234567890123457E+16" (sd-num-to-string 47.0815 2) => "47.08"
(sd-write-to-string any [digits])
(sd-write-to-string 57.0) => "57" (sd-write-to-string '(52.1 57.0)) => "(52.1 57)" (sd-write-to-string '(:deg 0 15 30 45 90) => "(:deg 0 15 30 45 90)" (sd-write-to-string 'sd-write-to-string)) => "oli::sd-write-to-string"
(sd-read-from-string string)
(sd-read-from-string "57.0") => 57.0 (sd-read-from-string "(52.1 57)") => (list 52.1 57)
(sd-string-match-pattern-p pattern string &optional :match-slash :match-leading-period :match-backslash)
(sd-string-match-pattern-p "[pP]art*" "Part4711") => T (sd-string-match-pattern-p "[a-z]*" "012_part") => NIL (sd-string-match-pattern-p "p?abc" "p23abc") => NIL (sd-string-match-pattern-p "dir*file*" "dir_a/dir_b/filename") => T (sd-string-match-pattern-p "dir*file*" "dir_a/dir_b/filename" :match-slash) => NIL
(sd-multi-lang-string default-string &optional language-pairs)
Use this function if you want to support more than one language with your add-on module. Wherever a string is expected, such as for a button title or prompt text of a dialog, use this function and Creo Elements/Direct Modeling picks the right localized string at runtime.
Note: In user/site/corp customization files like sd_avail_cmds.cmd or all toolbar/context menu definition files you must use the internal function (ui::multi-lang ...) which takes the same parameters as described here to achieve multi-language support within those files.
Note 2: If you run Creo Elements/Direct Modeling in a semi-supported language the
keyword which matches the language string as passed to the
$LANG or $SDLANG system variable can be used to define
a multi-lang string in that semi-supported language.
Example: (sd-multi-lang-string "Text in English" :chinese_s "Text in
simplified chinese")
Warning: sd-multi-lang-string will only work if the literal strings in the function call use a string encoding which matches the expectations of the Lisp reader.
If you load Lisp code from legacy-encoded files, the Lisp reader will assume by default that string literals in Lisp code are encoded according to the language which Creo Elements/Direct Modeling currently runs in. If you run Creo Elements/Direct Modeling in any of the supported Western languages (English, German, French etc.), and if you load the Lisp code from a non-Unicode file, all string literals in your code must be encoded in Roman8. If you run Creo Elements/Direct Modeling in Japanese, all string literals must be encoded according to Shift-JIS to be parsed properly, i.e. they can only contain Japanese and English characters, but no umlauts or accented characters.
If you mix SJIS- and Roman8-encoded string literals in a legacy-encoded file, chances are that the Lisp reader may report an error while your Lisp code is evaluated.
If you use sd-multi-lang-string in OneSpace Modeling 2007 and later, we recommend to encode the Lisp file which contains the function call either in UTF-8 or UTF-16, and to make sure that the file is marked with either a UTF-8 or UTF-16 byte-order mark (BOM). The Lisp reader will automatically detect the encoding when it finds the BOM, and will then process all literal strings in the file correctly (if, of course, they use either UTF-8 or UTF-16 encoding).
(sd-multi-lang-string "Text in English" :german "Text in German") if language of Creo Elements/Direct Modeling is English: => "Text in English" German: => "Text in German" French: => "Text in English" Italian: => "Text in English" Spanish: => "Text in English" Japanese: => "Text in English" (sd-multi-lang-string "Text in German" :french "Text in French" :italian "Text in Italian") if language of Creo Elements/Direct Modeling is English: => "Text in German" German: => "Text in German" French: => "Text in French" Italian: => "Text in Italian" Spanish: => "Text in German" Japanese: => "Text in German"
(sd-string-to-octets string :external-format encoding :calc-size calc-size) (sd-octets-to-string array :external-format encoding)
sd-string-to-octets converts strings from the internally used encoding into the encoding specified via :external-format. The result is an array of integer values which represent the string in the specified encoding.
sd-octets-to-string converts from the specified external encoding into the internal encoding. It expects an array of integer values as its input, where the integer values represent a string in the specified encoding. The result is a string in Creo Elements/Direct Modeling's internal encoding.
(oli:sd-octets-to-string (oli:sd-string-to-octets "Mötley Crüe" :external-format :utf-8) :external-format :utf-8))
(sd-recode-textfile from-filename from-encoding to-filename to-encoding)
(oli:sd-recode-textfile "utf8.txt" :utf-8 "utf-16.txt" :utf-16)
© 2023 Parametric
Technology GmbH (a subsidiary of PTC Inc.), All Rights Reserved |