| 1 | -- PseudoXMLPS |
|---|
| 2 | ----------------------------------- |
|---|
| 3 | -- CREATED: |
|---|
| 4 | -- 2002 |
|---|
| 5 | -- |
|---|
| 6 | -- DESCRIPTION: |
|---|
| 7 | -- Pseudo XML by Alex da Franca c2003 |
|---|
| 8 | -- Convert a lingo list to a XML like string and back |
|---|
| 9 | |
|---|
| 10 | -- |
|---|
| 11 | -- REQUIRES: |
|---|
| 12 | -- only the functions mSaveList_2_XML() and mReadXML_2_List() require my system of library scripts |
|---|
| 13 | -- in order to write and read text with fileio. All other functions have no dependencies |
|---|
| 14 | -- Either get these scripts from my website, or replace the write/read stuff with your own fileIO handlers |
|---|
| 15 | -- That is: |
|---|
| 16 | -- * movie script "aleXtrasMovieScript" |
|---|
| 17 | -- * parent script "commonMovieScript" |
|---|
| 18 | -- * parent script "FileIOFunktionen" |
|---|
| 19 | -- |
|---|
| 20 | -- USAGE: |
|---|
| 21 | -- ---------- please see the comments for each handler for a how-to. |
|---|
| 22 | -- ---------- nonetheless here are some fast start comments with the minimum amount of parameters |
|---|
| 23 | -- PseudoXMLPS = new(script "PseudoXMLPS") |
|---|
| 24 | -- -- Convert a list to an xml string: |
|---|
| 25 | -- xmlString = PseudoXMLPS.mGetXMLStringFromList(["one", "two", [#prop: 3]]) |
|---|
| 26 | -- lingolist = PseudoXMLPS.mGetListFromXMLString(xmlString) |
|---|
| 27 | -- ---------- basically that's it |
|---|
| 28 | -- |
|---|
| 29 | -- ---------- another "hack" to be aware of is the following: |
|---|
| 30 | -- ---------- linear lists get identified by having a nodename which starts with the exact string "item" |
|---|
| 31 | -- ---------- so if an xml node like <item1>one</item1> is encountered, it is treated as linear list: ["one"] |
|---|
| 32 | -- ---------- and NOT as [#item1:"one"] |
|---|
| 33 | -- |
|---|
| 34 | -- ---------- the mGetXMLStringFromList() function escapes the reserved xml chars <> and & and ' and " by default |
|---|
| 35 | -- ---------- if for some reason you rather want to enclose the contents in a <![CDATA[ tag, use the dontReplaceGT flag. |
|---|
| 36 | --------------------------------------------- EXAMPLE for <dontReplaceGT = 1> (dontReplaceGT means don't replace "greater than" btw...): |
|---|
| 37 | -- |
|---|
| 38 | -- myList = [#stringWithInvalidChars:"A string with invalid chars like <> and & and ' and " & QUOTE] |
|---|
| 39 | -- myList[#stringWithInvalidChars] = "<![CDATA[" & myList[#stringWithInvalidChars] & "]]>" |
|---|
| 40 | -- xmlString = PseudoXMLPS.mGetXMLStringFromList(myList, "myList", 1, 1) |
|---|
| 41 | -- ... |
|---|
| 42 | -- myList = PseudoXMLPS.mGetListFromXMLString(xmlString) |
|---|
| 43 | -- repeat with n = countmyList) down to 1 |
|---|
| 44 | -- thisValue = myList[n] |
|---|
| 45 | -- if ilk(thisValue) = #string then |
|---|
| 46 | -- if thisValue starts "<![CDATA[" then |
|---|
| 47 | -- delete char 1 to 9 of thisValue |
|---|
| 48 | -- delete char length(thisValue) - 2 to length(thisValue) of thisValue |
|---|
| 49 | -- myList[n] = thisValue |
|---|
| 50 | -- end if |
|---|
| 51 | -- end if |
|---|
| 52 | -- end repeat |
|---|
| 53 | --------------------------------------------- please note, that the above example is ONLY needed, if you use dontReplaceGT = 1 !! |
|---|
| 54 | -- |
|---|
| 55 | -- HISTORY: |
|---|
| 56 | |
|---|
| 57 | -- alex am Freitag 21.April.2006 16:31:57 |
|---|
| 58 | -- fixed a bug in "mBuildXMLString" many thanks to Olaf Schliesing for pointing this out |
|---|
| 59 | -- |
|---|
| 60 | -- alex am 28.11.06 um 16:41:00 |
|---|
| 61 | -- finally added a tag property, when writing xml, so the ilk of the object gets stored |
|---|
| 62 | -- so, when reading back the xml file, we do not convert a node by accident to a value |
|---|
| 63 | -- when a string evaluates to a value "by accident" |
|---|
| 64 | -- |
|---|
| 65 | -- Scriptmarker: changes alex (04.04.2007 at 10:22 Uhr) // Scriptmarker |
|---|
| 66 | -- added escaping of: |
|---|
| 67 | -- & -> & |
|---|
| 68 | -- ' -> ' |
|---|
| 69 | -- " -> " |
|---|
| 70 | -- and vice versa. Until now I only escaped < and >, but ampersand, apostrophe and quote must also be escaped for proper xml |
|---|
| 71 | -- I als added "support" for the CData tag, which allows you to escape the whole contents of a node. |
|---|
| 72 | -- support is only done through ignoring esaping the special characters, wehn BUILDING the xml string. |
|---|
| 73 | -- So the user can decide on his own, which nodes s/he wants to be masked inside a CData section |
|---|
| 74 | -- (otherwise I'd have to mask EVERY string and try to unmask EVERY node. Now the user is on his own) |
|---|
| 75 | -- TODO: |
|---|
| 76 | -- - |
|---|
| 77 | ----------------------------------- |
|---|
| 78 | |
|---|
| 79 | on _____________________PROPERTY_DECLARATION me |
|---|
| 80 | end |
|---|
| 81 | -- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
|---|
| 82 | property ancestor |
|---|
| 83 | property pXMLParserXtra |
|---|
| 84 | property pXmlxtraversion, pVersionNumber |
|---|
| 85 | |
|---|
| 86 | -- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
|---|
| 87 | on ___________________STANDARD_EVENTS me |
|---|
| 88 | end |
|---|
| 89 | -- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
|---|
| 90 | |
|---|
| 91 | on new me |
|---|
| 92 | Script_Root_Object = member("Script_Root_Object") |
|---|
| 93 | if ilk(Script_Root_Object) = #member then |
|---|
| 94 | if Script_Root_Object.type = #script then |
|---|
| 95 | ancestor = new(script "Script_Root_Object") |
|---|
| 96 | mSetScriptName me, "PseudoXMLPS" |
|---|
| 97 | end if |
|---|
| 98 | end if |
|---|
| 99 | return me |
|---|
| 100 | end |
|---|
| 101 | |
|---|
| 102 | -- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
|---|
| 103 | on ___________________ENGINE_EVENTS me |
|---|
| 104 | end |
|---|
| 105 | -- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
|---|
| 106 | |
|---|
| 107 | on mDestroy me |
|---|
| 108 | pXMLParserXtra = void |
|---|
| 109 | end |
|---|
| 110 | |
|---|
| 111 | -- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
|---|
| 112 | on ___________PUBLIC_EVENTS me |
|---|
| 113 | end |
|---|
| 114 | -- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
|---|
| 115 | |
|---|
| 116 | -- on handler me |
|---|
| 117 | --end |
|---|
| 118 | |
|---|
| 119 | -- on handlers me |
|---|
| 120 | --end |
|---|
| 121 | |
|---|
| 122 | on interface me |
|---|
| 123 | str = "Pseudo XML Script by alex da franca c2003 -- alex@farbflash.de -- all rigths reserved" |
|---|
| 124 | put RETURN & "version 1" after str |
|---|
| 125 | |
|---|
| 126 | put RETURN & "----- Translate lingoList to XML-ish string (docname and strict optional)" after str |
|---|
| 127 | put RETURN & "on mGetXMLStringFromList me, list_propOrlinearList, string_docName, boolean_strict" after str |
|---|
| 128 | put RETURN & "------------ RETURNS string" after str |
|---|
| 129 | put RETURN after str |
|---|
| 130 | |
|---|
| 131 | put RETURN & "----- Parse XML-ish string to lingo list" after str |
|---|
| 132 | put RETURN & "on mGetListFromXMLStringlingo me, string_XMLstring, integer_convertValues" after str |
|---|
| 133 | put RETURN & "-- -- <convertValues> #integer" after str |
|---|
| 134 | put RETURN & "-- -- -- 0 => don't convert (fast, all values are strings)" after str |
|---|
| 135 | put RETURN & "-- -- -- 1 => convert only integer() and float() (slower)" after str |
|---|
| 136 | put RETURN & "-- -- -- 2 => try to convert all data with value(), even parse for colors in hexstring format (slow)" after str |
|---|
| 137 | put RETURN & "------------ RETURNS property list" after str |
|---|
| 138 | put RETURN after str |
|---|
| 139 | |
|---|
| 140 | put RETURN & "----- Parse XML string to lingo list using XML xtra:" after str |
|---|
| 141 | put RETURN & "on mGetListFromXMLString me, string_XMLstring, integer_convertValues" after str |
|---|
| 142 | put RETURN & "-- -- <convertValues> #integer" after str |
|---|
| 143 | put RETURN & "-- -- -- 0 => don't convert (fast, all values are strings)" after str |
|---|
| 144 | put RETURN & "-- -- -- 1 => convert only integer() and float() (slower)" after str |
|---|
| 145 | put RETURN & "-- -- -- 2 => try to convert all data with value(), even parse for colors in hexstring format (slow)" after str |
|---|
| 146 | put RETURN & "------------ RETURNS property list" after str |
|---|
| 147 | put RETURN after str |
|---|
| 148 | |
|---|
| 149 | put RETURN & "----- Read Apple-style plist file and convert it to a lingo property list:" after str |
|---|
| 150 | put RETURN & "on mReadPList me, string_Filename" after str |
|---|
| 151 | put RETURN & "-- -- -- <Filename> is optional, if not present a file selection dialog is displayed" after str |
|---|
| 152 | put RETURN & "------------ RETURNS property list" after str |
|---|
| 153 | put RETURN after str |
|---|
| 154 | |
|---|
| 155 | put RETURN & "----- Convert Apple-style plist file to lingo list:" after str |
|---|
| 156 | put RETURN & "on mGetListFromPListString me, string_pListString" after str |
|---|
| 157 | put RETURN & "------------ RETURNS property list" after str |
|---|
| 158 | put RETURN after str |
|---|
| 159 | |
|---|
| 160 | -- put RETURN & "----- Convert Apple-style plist to lingo list (after converting the .plist file with mGetListFromXMLStringX):" after str |
|---|
| 161 | -- put RETURN & "proplist mConvertKeyList object me, proplist inputlist" after str |
|---|
| 162 | -- put RETURN after str |
|---|
| 163 | |
|---|
| 164 | put RETURN & "----- Parse Excel style XML data (for now it parses only the first worksheet with the XMLParser Xtra):" after str |
|---|
| 165 | put RETURN & "on mParseExcelXML me, string_theText" after str |
|---|
| 166 | put RETURN & "------------ RETURNS property list" after str |
|---|
| 167 | |
|---|
| 168 | return str |
|---|
| 169 | end |
|---|
| 170 | |
|---|
| 171 | |
|---|
| 172 | -- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
|---|
| 173 | -- xxxxxxxxxxxxxxxxxx Convert lingo list (also nested lists) to XML stylish string |
|---|
| 174 | |
|---|
| 175 | on mGetXMLStringFromList me, listref, docName, strict, dontReplaceGT, withParams |
|---|
| 176 | ----------------------------------- |
|---|
| 177 | -- CREATED: 06.03.2008 |
|---|
| 178 | -- ACTION: Convert lingo list (also nested lists) to XML stylish string |
|---|
| 179 | -- INPUT: |
|---|
| 180 | -- <listref> format: property list or linear list |
|---|
| 181 | -- <docName> format: #string; optional. if omitted "Untitled" is used for the XML document name |
|---|
| 182 | -- <strict> => boolean; avoid spaces in tag names |
|---|
| 183 | -- <dontReplaceGT> => boolean; dont replace < and > |
|---|
| 184 | -- <withParams> => boolean; write attribute in tag for the lingo ilk => bigger xml files and unfortunately it is slower to parse |
|---|
| 185 | ----------------------------- (I thought avoiding value() would help, but in this case the additional text parsing of the attributes tag slows down) |
|---|
| 186 | -- RETURNS: string |
|---|
| 187 | -- EXAMPLE: saveString = mGetXMLStringFromList(me, lingo_list, "documentName") |
|---|
| 188 | ----------------------------------- |
|---|
| 189 | |
|---|
| 190 | -- ms = the milliseconds |
|---|
| 191 | if voidP(strict) then strict = 0 |
|---|
| 192 | |
|---|
| 193 | -- if the last char of the moviepath = ":" then |
|---|
| 194 | -- str = "<?xml version=""E&"1.0""E&&"encoding=""E&"macintosh""E&&"?>"&RETURN |
|---|
| 195 | -- else |
|---|
| 196 | -- str = "<?xml version=""E&"1.0""E&&"encoding=""E&"ISO-8859-1""E&&"?>"&RETURN |
|---|
| 197 | -- end if |
|---|
| 198 | str = "<?xml version=""E&"1.0""E&&"encoding=""E&"ISO-8859-1""E&&"?>"&RETURN |
|---|
| 199 | |
|---|
| 200 | if not(string(docName).length) then docName = "Untitled" |
|---|
| 201 | if not("abcdefghijklmnopqrstuvwxyz_" contains char 1 of docname) then put "a" before docname |
|---|
| 202 | put "<" & docName & ">" & RETURN after str |
|---|
| 203 | |
|---|
| 204 | if the platform contains "mac" then |
|---|
| 205 | put mMapCharCodes(me, mBuildXMLString(me, listref, 1, strict, dontReplaceGT, withParams), #mac2win) after str |
|---|
| 206 | else |
|---|
| 207 | put mBuildXMLString(me, listref, 1, strict, dontReplaceGT, withParams) after str |
|---|
| 208 | end if |
|---|
| 209 | |
|---|
| 210 | put "</" & docName & ">" after str |
|---|
| 211 | -- put the milliseconds - ms |
|---|
| 212 | return str |
|---|
| 213 | end |
|---|
| 214 | |
|---|
| 215 | |
|---|
| 216 | -- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
|---|
| 217 | -- xxxxxxxxxxxxxxxxxx Convert XML stylish string to lingo list |
|---|
| 218 | |
|---|
| 219 | |
|---|
| 220 | on mGetListFromXMLStringlingo me, str, convertValues, withParams |
|---|
| 221 | ----------------------------------- |
|---|
| 222 | -- CREATED: 06.03.2008 |
|---|
| 223 | -- ACTION: Description |
|---|
| 224 | -- INPUT: |
|---|
| 225 | -- <str> format: #string; split a string using <> and </> tags into lingo list |
|---|
| 226 | -- <convertValues> #integer 0=>don't convert (fast, all values are strings), 1 => convert only numbers (slower); 2 => try to convert all data, even colors (slow) |
|---|
| 227 | -- <withParams> : #boolean : parse parameters too. new, not very well tested |
|---|
| 228 | -- RETURNS: property list |
|---|
| 229 | -- EXAMPLE: lingo_list = mGetListFromXMLStringlingo(me, saveString) |
|---|
| 230 | -- CHANGES: implemented parameter parsing |
|---|
| 231 | ----------------------------------- |
|---|
| 232 | |
|---|
| 233 | ms = the milliseconds |
|---|
| 234 | |
|---|
| 235 | if ilk(str) <> #string then str = string(str) |
|---|
| 236 | |
|---|
| 237 | if voidP(convertValues) then convertValues = 2 |
|---|
| 238 | |
|---|
| 239 | if the platform contains "mac" then |
|---|
| 240 | if str.line[1] contains "encoding=""E&"ISO-8859-1""E then |
|---|
| 241 | str = mMapCharCodes(me, str, #win2mac) |
|---|
| 242 | end if |
|---|
| 243 | end if |
|---|
| 244 | |
|---|
| 245 | str = mRemoveXMLComments(me, str) |
|---|
| 246 | |
|---|
| 247 | |
|---|
| 248 | offs = offset("<", str) |
|---|
| 249 | if offs > 0 then |
|---|
| 250 | if offs > 1 then delete char 1 to (offs - 1) of str |
|---|
| 251 | offs = offset(">", str) |
|---|
| 252 | if offs > 0 then |
|---|
| 253 | selector = char 2 to (offs - 1) of str |
|---|
| 254 | retlist = mParseXMLString(me, str, selector, convertValues) |
|---|
| 255 | -- put the milliseconds - ms |
|---|
| 256 | return retlist[1].getaprop(symbol(selector)) |
|---|
| 257 | end if |
|---|
| 258 | end if |
|---|
| 259 | -- put the milliseconds - ms |
|---|
| 260 | return [:] |
|---|
| 261 | end |
|---|
| 262 | |
|---|
| 263 | |
|---|
| 264 | -- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
|---|
| 265 | -- this is just backward compatibility with older scripts |
|---|
| 266 | |
|---|
| 267 | on mGetListFromXMLStringX me, str, convertValues, withParams |
|---|
| 268 | return mGetListFromXMLString(me, str, convertValues, withParams) |
|---|
| 269 | end |
|---|
| 270 | |
|---|
| 271 | -- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
|---|
| 272 | |
|---|
| 273 | on mGetListFromXMLString me, str, convertValues, withParams |
|---|
| 274 | ----------------------------------- |
|---|
| 275 | -- CREATED: 06.03.2008 |
|---|
| 276 | -- ACTION: Convert xml string to lingo list using the xmlparser xtra, if possible |
|---|
| 277 | -- MUCH FASTER than the above: Use the XML xtra to parse the string |
|---|
| 278 | -- BUT it must be a valid xml string, the above is slower but allows more malformed xml |
|---|
| 279 | -- INPUT: |
|---|
| 280 | -- <str> format: #string; split a string using <> and </> tags into lingo list |
|---|
| 281 | -- <convertValues> #integer |
|---|
| 282 | -- -- -- 0 => don't convert (fast, all values are strings) |
|---|
| 283 | -- -- -- 1 => convert only integer() and float() (slower) |
|---|
| 284 | -- -- -- 2 => try to convert all data with value(), even parse for colors in hexstring format (slow) |
|---|
| 285 | -- RETURNS: property list |
|---|
| 286 | -- EXAMPLE: lingo_list = mGetListFromXMLString(me, saveString) |
|---|
| 287 | -- CHANGES: resorts to the slower lingo function on xml parser error. So this handler can always be used. |
|---|
| 288 | ----------------------------------- |
|---|
| 289 | |
|---|
| 290 | if ilk(str) <> #string then str = string(str) |
|---|
| 291 | |
|---|
| 292 | ------------------ First check for the XML Parser xtra version 10 |
|---|
| 293 | if voidP(pXmlxtraversion) then |
|---|
| 294 | |
|---|
| 295 | listOfXtras = the xtraList |
|---|
| 296 | pXmlxtraversion = "" |
|---|
| 297 | repeat with currentXtra in listOfXtras |
|---|
| 298 | theName = string(currentXtra.getaprop(#filename)) |
|---|
| 299 | if length(theName) < 1 then theName = string(currentXtra.getaprop(#name)) |
|---|
| 300 | if theName contains "XmlParser" then |
|---|
| 301 | pXmlxtraversion =string(currentXtra.getaprop(#version)) |
|---|
| 302 | exit repeat |
|---|
| 303 | end if |
|---|
| 304 | end repeat |
|---|
| 305 | |
|---|
| 306 | if length(pXmlxtraversion) then |
|---|
| 307 | offs = offset(".", pXmlxtraversion) |
|---|
| 308 | if offs > 0 then |
|---|
| 309 | intVers = char 1 to offs of pXmlxtraversion |
|---|
| 310 | delete char 1 to offs of pXmlxtraversion |
|---|
| 311 | else |
|---|
| 312 | intVers = "" |
|---|
| 313 | end if |
|---|
| 314 | cnt = length(pXmlxtraversion) |
|---|
| 315 | repeat with n = 1 to cnt |
|---|
| 316 | c = pXmlxtraversion.char[n] |
|---|
| 317 | if integerP(integer(c)) then |
|---|
| 318 | put c after intVers |
|---|
| 319 | else if c <> "." then |
|---|
| 320 | exit repeat |
|---|
| 321 | end if |
|---|
| 322 | end repeat |
|---|
| 323 | |
|---|
| 324 | pXmlxtraversion = value(intVers) |
|---|
| 325 | else |
|---|
| 326 | pXmlxtraversion = 0 |
|---|
| 327 | end if |
|---|
| 328 | |
|---|
| 329 | end if |
|---|
| 330 | |
|---|
| 331 | if pXmlxtraversion < 10 then return mGetListFromXMLStringlingo(me, str, convertValues, withParams) |
|---|
| 332 | ------------------ end XML Parser xtra version 10 check |
|---|
| 333 | |
|---|
| 334 | |
|---|
| 335 | ms = the milliseconds |
|---|
| 336 | |
|---|
| 337 | if voidP(convertValues) then convertValues = 2 |
|---|
| 338 | |
|---|
| 339 | offs = offset("<", str) |
|---|
| 340 | if offs < 1 then return [:] |
|---|
| 341 | if offs > 1 then delete char 1 to (offs - 1) of str |
|---|
| 342 | offs = offset("<?xml", str) |
|---|
| 343 | if offs <> 1 then |
|---|
| 344 | offs = offset("<? xml", str) |
|---|
| 345 | if offs <> 1 then |
|---|
| 346 | put "<?xml version=""E&"1.0""E&&"encoding=""E&"ISO-8859-1""E&&"?>"&RETURN before str |
|---|
| 347 | end if |
|---|
| 348 | end if |
|---|
| 349 | |
|---|
| 350 | |
|---|
| 351 | if not(objectP(pXMLParserXtra)) then pXMLParserXtra = new(xtra "XmlParser") |
|---|
| 352 | pXMLParserXtra.parseString(str) |
|---|
| 353 | |
|---|
| 354 | if not(voidP(pXMLParserXtra.getError())) then |
|---|
| 355 | put "Script: PseudoXMLPS; Handler: mGetListFromXMLString; error:" && pXMLParserXtra.getError() |
|---|
| 356 | return mGetListFromXMLStringlingo(me, str, convertValues, withParams) |
|---|
| 357 | end if |
|---|
| 358 | |
|---|
| 359 | xx = pXMLParserXtra.makePropList() |
|---|
| 360 | dontEscapeSpecialChars = 1 -- we do not need to do this, as the xmlparser xtra already did it for us |
|---|
| 361 | li = mConvertXMLPropList(me, [xx], convertValues, dontEscapeSpecialChars) |
|---|
| 362 | |
|---|
| 363 | -- put "PseudoXMLPS: mGetListFromXMLString:" && the milliseconds - ms |
|---|
| 364 | |
|---|
| 365 | if not(listP(li)) then return [:] |
|---|
| 366 | if count(li) < 1 then return [:] |
|---|
| 367 | return li[1] |
|---|
| 368 | |
|---|
| 369 | end |
|---|
| 370 | |
|---|
| 371 | -- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
|---|
| 372 | on _______________READ_WRITE_EXTERNAL_FILES |
|---|
| 373 | end |
|---|
| 374 | -- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
|---|
| 375 | |
|---|
| 376 | on mReadXML_2_List me, thePath |
|---|
| 377 | ----------------------------------- |
|---|
| 378 | -- CREATED: 06.03.2008 |
|---|
| 379 | -- ACTION: read external xml file to lingo list |
|---|
| 380 | -- INPUT: <thePath> : string ; optional pathname. if no pathname or "", then a file save dialog is shown |
|---|
| 381 | -- RETURNS: property list |
|---|
| 382 | ----------------------------------- |
|---|
| 383 | |
|---|
| 384 | dertext = xscr(#FileIOFunktionen).mGetTextFromFile(thePath, void, "windows-1252") |
|---|
| 385 | if length(dertext) > 0 then return mGetListFromXMLString(me, dertext) |
|---|
| 386 | return [:] |
|---|
| 387 | end |
|---|
| 388 | |
|---|
| 389 | -- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
|---|
| 390 | |
|---|
| 391 | on mSaveList_2_XML me, theList, thePath |
|---|
| 392 | ----------------------------------- |
|---|
| 393 | -- CREATED: 06.03.2008 |
|---|
| 394 | -- ACTION: write liongo list to external xml file |
|---|
| 395 | -- INPUT: |
|---|
| 396 | -- <theList> : linear or property list |
|---|
| 397 | -- <thePath> : string ; optional pathname. if no pathname or "", then a file selection dialog is shown |
|---|
| 398 | -- RETURNS: full pathname of newly created file, if successful, otherwise 0 |
|---|
| 399 | ----------------------------------- |
|---|
| 400 | |
|---|
| 401 | if not(listP(theList)) then return 0 |
|---|
| 402 | theResult = mGetXMLStringFromList(me, theList) |
|---|
| 403 | return xscr(#FileIOFunktionen).mSaveToTextFile(theResult, thePath) |
|---|
| 404 | end |
|---|
| 405 | |
|---|
| 406 | |
|---|
| 407 | -- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
|---|
| 408 | -- xxxxxxxxxxxxxxxxxx Privat Handlers |
|---|
| 409 | -- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
|---|
| 410 | -- (used recursively for mGetXMLStringFromList() and mGetListFromXMLString()) |
|---|
| 411 | |
|---|
| 412 | |
|---|
| 413 | on mBuildXMLString me, eineListe, tiefe, strict, dontReplaceGT, withParams |
|---|
| 414 | praefix = "" |
|---|
| 415 | if ilk(tiefe) = #integer then |
|---|
| 416 | t2 = tiefe + 1 |
|---|
| 417 | repeat with n = 1 to tiefe |
|---|
| 418 | put TAB after praefix |
|---|
| 419 | end repeat |
|---|
| 420 | else |
|---|
| 421 | t2 = void |
|---|
| 422 | end if |
|---|
| 423 | |
|---|
| 424 | anz = count(eineListe) |
|---|
| 425 | prop = (ilk(eineListe) = #propList) |
|---|
| 426 | |
|---|
| 427 | str = "" |
|---|
| 428 | repeat with n = 1 to anz |
|---|
| 429 | if prop then |
|---|
| 430 | ident = eineListe.getPropAt(n) |
|---|
| 431 | if strict then |
|---|
| 432 | if [#symbol, #integer, #float].getPos(ilk(ident)) < 1 then |
|---|
| 433 | ident = string(ident) |
|---|
| 434 | offs = offset(SPACE, ident) |
|---|
| 435 | repeat while offs |
|---|
| 436 | put "_" into char offs of ident |
|---|
| 437 | offs = offset(SPACE, ident) |
|---|
| 438 | end repeat |
|---|
| 439 | end if |
|---|
| 440 | end if |
|---|
| 441 | else |
|---|
| 442 | ident = "item"&n |
|---|
| 443 | end if |
|---|
| 444 | |
|---|
| 445 | val = eineListe[n] |
|---|
| 446 | theIlk = ilk(val) |
|---|
| 447 | |
|---|
| 448 | if withParams then |
|---|
| 449 | put praefix & "<" & ident && "ilk=" & QUOTE & theIlk & QUOTE & ">" after str |
|---|
| 450 | else |
|---|
| 451 | put praefix & "<" & ident & ">" after str |
|---|
| 452 | end if |
|---|
| 453 | |
|---|
| 454 | suffix = "" |
|---|
| 455 | case theIlk of |
|---|
| 456 | -- alex am Freitag 21.April.2006 16:31:57 |
|---|
| 457 | -------------------------------------------------------- |
|---|
| 458 | #list: |
|---|
| 459 | if count(val) then |
|---|
| 460 | put RETURN after str |
|---|
| 461 | put mBuildXMLString(me, val, t2, strict, dontReplaceGT, withParams) after str -- <- rekursiv |
|---|
| 462 | suffix = praefix |
|---|
| 463 | else |
|---|
| 464 | put "[]" after str |
|---|
| 465 | end if |
|---|
| 466 | #proplist: |
|---|
| 467 | if count(val) then |
|---|
| 468 | put RETURN after str |
|---|
| 469 | put mBuildXMLString(me, val, t2, strict, dontReplaceGT, withParams) after str -- <- rekursiv |
|---|
| 470 | suffix = praefix |
|---|
| 471 | else |
|---|
| 472 | put "[:]" after str |
|---|
| 473 | end if |
|---|
| 474 | -------------------------------------------------------- |
|---|
| 475 | -- // alex am Freitag 21.April.2006 16:31:57 |
|---|
| 476 | #color: |
|---|
| 477 | put val.hexstring() after str |
|---|
| 478 | #symbol: |
|---|
| 479 | put "#" & val after str |
|---|
| 480 | otherwise |
|---|
| 481 | if not dontReplaceGT then -- in this case I needed "<![CDATA[02]]>" and so do not convert < and > |
|---|
| 482 | |
|---|
| 483 | -- escape <>&'" |
|---|
| 484 | val = mEscapeSpecialChars(me, val) |
|---|
| 485 | |
|---|
| 486 | end if |
|---|
| 487 | put val after str |
|---|
| 488 | end case |
|---|
| 489 | put suffix & "</" & ident & ">" & RETURN after str |
|---|
| 490 | end repeat |
|---|
| 491 | |
|---|
| 492 | return str |
|---|
| 493 | end |
|---|
| 494 | |
|---|
| 495 | |
|---|
| 496 | -- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
|---|
| 497 | |
|---|
| 498 | on mParseXMLString me, str, selector, convertValues |
|---|
| 499 | |
|---|
| 500 | offs = offset("<", str) |
|---|
| 501 | |
|---|
| 502 | if offs > 0 then |
|---|
| 503 | delete char 1 to offs of str |
|---|
| 504 | offs = offset(">", str) |
|---|
| 505 | if offs > 0 then |
|---|
| 506 | sel = char 1 to (offs - 1) of str |
|---|
| 507 | |
|---|
| 508 | attr = "" |
|---|
| 509 | theparams = sel.word[2 .. sel.word.count] |
|---|
| 510 | if length(theparams) > 0 then |
|---|
| 511 | poffs = offset("=", theparams) |
|---|
| 512 | if poffs > 0 then |
|---|
| 513 | if char 1 to poffs-1 of theparams = "ilk" then |
|---|
| 514 | attr = char poffs+1 to length(theparams) of theparams |
|---|
| 515 | if length(attr) > 0 then |
|---|
| 516 | if char 1 of attr = QUOTE then delete char 1 of attr |
|---|
| 517 | if length(attr) > 0 then |
|---|
| 518 | if the last char of attr = QUOTE then delete the last char of attr |
|---|
| 519 | end if |
|---|
| 520 | end if |
|---|
| 521 | end if |
|---|
| 522 | end if |
|---|
| 523 | end if |
|---|
| 524 | |
|---|
| 525 | sel = sel.word[1] |
|---|
| 526 | |
|---|
| 527 | if offset("item", sel) = 1 then retlist = [] |
|---|
| 528 | else retlist = [:] |
|---|
| 529 | |
|---|
| 530 | delete char 1 to offs of str |
|---|
| 531 | |
|---|
| 532 | offs = offset("<", str) |
|---|
| 533 | repeat while offs > 0 |
|---|
| 534 | |
|---|
| 535 | |
|---|
| 536 | if the last char of sel = "/" then |
|---|
| 537 | |
|---|
| 538 | delete the last char of sel |
|---|
| 539 | |
|---|
| 540 | if ilk(retList) = #proplist then |
|---|
| 541 | retList.addProp(symbol(sel), 1) |
|---|
| 542 | else |
|---|
| 543 | retList.add(1) |
|---|
| 544 | end if |
|---|
| 545 | |
|---|
| 546 | if char (offs + 1) of str = "/" then |
|---|
| 547 | delete char 1 to (offs - 1) of str |
|---|
| 548 | offs = offset(">", str) |
|---|
| 549 | if offs > 0 then |
|---|
| 550 | delete char 1 to offs of str |
|---|
| 551 | end if |
|---|
| 552 | |
|---|
| 553 | repeat while str.length |
|---|
| 554 | if ([SPACE, TAB, RETURN].getPos(str.char[1]) > 0) then |
|---|
| 555 | delete char 1 of str |
|---|
| 556 | else |
|---|
| 557 | exit repeat |
|---|
| 558 | end if |
|---|
| 559 | end repeat |
|---|
| 560 | |
|---|
| 561 | exit repeat |
|---|
| 562 | else |
|---|
| 563 | delete char 1 to offs of str |
|---|
| 564 | offs = offset(">", str) |
|---|
| 565 | if offs > 0 then |
|---|
| 566 | sel = char 1 to (offs - 1) of str |
|---|
| 567 | -- theparams = sel.word[2 .. sel.word.count] |
|---|
| 568 | sel = sel.word[1] |
|---|
| 569 | |
|---|
| 570 | delete char 1 to offs of str |
|---|
| 571 | |
|---|
| 572 | offs = offset("<", str) |
|---|
| 573 | |
|---|
| 574 | else |
|---|
| 575 | exit repeat |
|---|
| 576 | end if |
|---|
| 577 | end if |
|---|
| 578 | |
|---|
| 579 | |
|---|
| 580 | |
|---|
| 581 | else if char (offs + 1) to (offs + 1 + sel.length) of str = "/"&sel then |
|---|
| 582 | |
|---|
| 583 | if offs > 1 then val = char 1 to (offs - 1) of str |
|---|
| 584 | else val = "" |
|---|
| 585 | |
|---|
| 586 | delete char 1 to (offs + 2 + sel.length) of str |
|---|
| 587 | repeat while str.length |
|---|
| 588 | if ([SPACE, TAB, RETURN].getPos(str.char[1]) > 0) then |
|---|
| 589 | delete char 1 of str |
|---|
| 590 | else |
|---|
| 591 | exit repeat |
|---|
| 592 | end if |
|---|
| 593 | end repeat |
|---|
| 594 | |
|---|
| 595 | |
|---|
| 596 | |
|---|
| 597 | |
|---|
| 598 | if length(attr) > 0 then |
|---|
| 599 | |
|---|
| 600 | attr = symbol(attr) |
|---|
| 601 | case attr of |
|---|
| 602 | #string: |
|---|
| 603 | |
|---|
| 604 | -- unescape <>&'" |
|---|
| 605 | val = mUnEscapeSpecialChars(me, val) |
|---|
| 606 | |
|---|
| 607 | |
|---|
| 608 | #integer: |
|---|
| 609 | val = integer(val) |
|---|
| 610 | #float: |
|---|
| 611 | val = float(val) |
|---|
| 612 | otherwise |
|---|
| 613 | v2 = value(val) |
|---|
| 614 | if ilk(v2) <> attr then val = void |
|---|
| 615 | |
|---|
| 616 | end case |
|---|
| 617 | |
|---|
| 618 | else |
|---|
| 619 | |
|---|
| 620 | -- simple case, only check for integer and float values: |
|---|
| 621 | if convertValues = 1 then |
|---|
| 622 | |
|---|
| 623 | v2 = mConvertToNumber(me, val) |
|---|
| 624 | if voidP(v2) then |
|---|
| 625 | |
|---|
| 626 | -- unescape <>&'" |
|---|
| 627 | val = mUnEscapeSpecialChars(me, val) |
|---|
| 628 | |
|---|
| 629 | else |
|---|
| 630 | val = v2 |
|---|
| 631 | end if |
|---|
| 632 | |
|---|
| 633 | |
|---|
| 634 | -- slower case, check for hex color values and value(): |
|---|
| 635 | else if convertValues = 2 then |
|---|
| 636 | |
|---|
| 637 | v2 = mFindIlk(me, val) |
|---|
| 638 | if voidP(v2) then |
|---|
| 639 | |
|---|
| 640 | -- unescape <>&'" |
|---|
| 641 | val = mUnEscapeSpecialChars(me, val) |
|---|
| 642 | |
|---|
| 643 | else |
|---|
| 644 | val = v2 |
|---|
| 645 | end if |
|---|
| 646 | |
|---|
| 647 | |
|---|
| 648 | else |
|---|
| 649 | |
|---|
| 650 | -- unescape <>&'" |
|---|
| 651 | val = mUnEscapeSpecialChars(me, val) |
|---|
| 652 | |
|---|
| 653 | |
|---|
| 654 | end if |
|---|
| 655 | |
|---|
| 656 | end if -- attr found |
|---|
| 657 | |
|---|
| 658 | |
|---|
| 659 | if ilk(retList) = #proplist then |
|---|
| 660 | retList.addProp(symbol(sel), val) |
|---|
| 661 | else |
|---|
| 662 | retList.add(val) |
|---|
| 663 | end if |
|---|
| 664 | |
|---|
| 665 | offs = offset("<", str) |
|---|
| 666 | |
|---|
| 667 | if offs > 0 then |
|---|
| 668 | if char (offs + 1) of str = "/" then |
|---|
| 669 | delete char 1 to (offs - 1) of str |
|---|
| 670 | offs = offset(">", str) |
|---|
| 671 | if offs > 0 then |
|---|
| 672 | delete char 1 to offs of str |
|---|
| 673 | end if |
|---|
| 674 | |
|---|
| 675 | repeat while str.length |
|---|
| 676 | if ([SPACE, TAB, RETURN].getPos(str.char[1]) > 0) then |
|---|
| 677 | delete char 1 of str |
|---|
| 678 | else |
|---|
| 679 | exit repeat |
|---|
| 680 | end if |
|---|
| 681 | end repeat |
|---|
| 682 | |
|---|
| 683 | exit repeat |
|---|
| 684 | else |
|---|
| 685 | delete char 1 to offs of str |
|---|
| 686 | offs = offset(">", str) |
|---|
| 687 | if offs > 0 then |
|---|
| 688 | sel = char 1 to (offs - 1) of str |
|---|
| 689 | -- theparams = sel.word[2 .. sel.word.count] |
|---|
| 690 | sel = sel.word[1] |
|---|
| 691 | |
|---|
| 692 | delete char 1 to offs of str |
|---|
| 693 | |
|---|
| 694 | offs = offset("<", str) |
|---|
| 695 | |
|---|
| 696 | else |
|---|
| 697 | exit repeat |
|---|
| 698 | end if |
|---|
| 699 | end if |
|---|
| 700 | else |
|---|
| 701 | exit repeat |
|---|
| 702 | end if |
|---|
| 703 | |
|---|
| 704 | else if char (offs + 1) to (offs + 1 + selector.length) of str = "/"&selector then |
|---|
| 705 | |
|---|
| 706 | delete char 1 to (offs + 2 + selector.length) of str |
|---|
| 707 | |
|---|
| 708 | repeat while str.length |
|---|
| 709 | if ([SPACE, TAB, RETURN].getPos(str.char[1]) > 0) then |
|---|
| 710 | delete char 1 of str |
|---|
| 711 | else |
|---|
| 712 | exit repeat |
|---|
| 713 | end if |
|---|
| 714 | end repeat |
|---|
| 715 | |
|---|
| 716 | exit repeat |
|---|
| 717 | else |
|---|
| 718 | strLi = mParseXMLString(me, str, sel, convertValues) |
|---|
| 719 | |
|---|
| 720 | if ilk(retList) = #proplist then |
|---|
| 721 | retList.addProp(symbol(sel), strLi[1]) |
|---|
| 722 | else |
|---|
| 723 | retList.add(strLi[1]) |
|---|
| 724 | end if |
|---|
| 725 | |
|---|
| 726 | str = strLi[2] |
|---|
| 727 | |
|---|
| 728 | offs = offset("<", str) |
|---|
| 729 | |
|---|
| 730 | if offs > 0 then |
|---|
| 731 | if char (offs + 1) of str = "/" then |
|---|
| 732 | delete char 1 to (offs - 1) of str |
|---|
| 733 | offs = offset(">", str) |
|---|
| 734 | if offs > 0 then |
|---|
| 735 | delete char 1 to offs of str |
|---|
| 736 | end if |
|---|
| 737 | |
|---|
| 738 | repeat while str.length |
|---|
| 739 | if ([SPACE, TAB, RETURN].getPos(str.char[1]) > 0) then |
|---|
| 740 | delete char 1 of str |
|---|
| 741 | else |
|---|
| 742 | exit repeat |
|---|
| 743 | end if |
|---|
| 744 | end repeat |
|---|
| 745 | |
|---|
| 746 | exit repeat |
|---|
| 747 | else |
|---|
| 748 | delete char 1 to offs of str |
|---|
| 749 | offs = offset(">", str) |
|---|
| 750 | if offs > 0 then |
|---|
| 751 | sel = char 1 to (offs - 1) of str |
|---|
| 752 | -- theparams = sel.word[2 .. sel.word.count] |
|---|
| 753 | sel = sel.word[1] |
|---|
| 754 | |
|---|
| 755 | delete char 1 to offs of str |
|---|
| 756 | |
|---|
| 757 | offs = offset("<", str) |
|---|
| 758 | |
|---|
| 759 | else |
|---|
| 760 | exit repeat |
|---|
| 761 | end if |
|---|
| 762 | end if |
|---|
| 763 | else |
|---|
| 764 | exit repeat |
|---|
| 765 | end if |
|---|
| 766 | |
|---|
| 767 | end if |
|---|
| 768 | |
|---|
| 769 | end repeat |
|---|
| 770 | |
|---|
| 771 | return [retList, str] |
|---|
| 772 | end if |
|---|
| 773 | |
|---|
| 774 | end if |
|---|
| 775 | |
|---|
| 776 | return [[], str] |
|---|
| 777 | end |
|---|
| 778 | |
|---|
| 779 | -- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
|---|
| 780 | |
|---|
| 781 | on mConvertToNumber me, val |
|---|
| 782 | if voidP(val) then return void |
|---|
| 783 | |
|---|
| 784 | val = word 1 to the number of words of val of val |
|---|
| 785 | len = length(val) |
|---|
| 786 | if len < 1 then return void |
|---|
| 787 | |
|---|
| 788 | v2 = integer(val) |
|---|
| 789 | if integerP(v2) then |
|---|
| 790 | |
|---|
| 791 | if val = "-" then return void |
|---|
| 792 | if length(string(v2)) <> len then return void |
|---|
| 793 | |
|---|
| 794 | return v2 |
|---|
| 795 | end if |
|---|
| 796 | |
|---|
| 797 | v2 = float(val) |
|---|
| 798 | if floatP(v2) then |
|---|
| 799 | |
|---|
| 800 | -- if length(string(v2)) <> len then return void |
|---|
| 801 | |
|---|
| 802 | return v2 |
|---|
| 803 | end if |
|---|
| 804 | |
|---|
| 805 | return void |
|---|
| 806 | end |
|---|
| 807 | |
|---|
| 808 | -- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
|---|
| 809 | |
|---|
| 810 | on mFindIlk me, val |
|---|
| 811 | if voidP(val) then return void |
|---|
| 812 | |
|---|
| 813 | if val.length = 7 then |
|---|
| 814 | if (val.char[1] = "#") then |
|---|
| 815 | isColor = 1 |
|---|
| 816 | repeat with n = 2 to 7 |
|---|
| 817 | if (offset(val.char[n], "abcdef0123456789") < 1) then |
|---|
| 818 | isColor = 0 |
|---|
| 819 | exit repeat |
|---|
| 820 | end if |
|---|
| 821 | end repeat |
|---|
| 822 | if isColor = 1 then return rgb(val) |
|---|
| 823 | end if |
|---|
| 824 | end if |
|---|
| 825 | |
|---|
| 826 | v2 = mConvertToNumber(me, val) |
|---|
| 827 | if not(voidP(v2)) then return v2 |
|---|
| 828 | |
|---|
| 829 | if val = "" then return val |
|---|
| 830 | |
|---|
| 831 | v2 = value(val) |
|---|
| 832 | |
|---|
| 833 | if [#vector, #rect, #point, #float].getPos(ilk(v2)) then return v2 |
|---|
| 834 | |
|---|
| 835 | if abs(length(string(v2)) - length(val)) > 1 then return void -- in case of symbols the # gets stripped, when we use the string() function |
|---|
| 836 | |
|---|
| 837 | return v2 |
|---|
| 838 | end |
|---|
| 839 | |
|---|
| 840 | |
|---|
| 841 | -- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
|---|
| 842 | |
|---|
| 843 | on mRemoveXMLComments me, str |
|---|
| 844 | -- remove comments: |
|---|
| 845 | -- version: |
|---|
| 846 | offs = offset("<?", str) |
|---|
| 847 | repeat while offs |
|---|
| 848 | ende = offset("?>", str) |
|---|
| 849 | if ende > 0 then |
|---|
| 850 | delete char offs to (ende + 1) of str |
|---|
| 851 | else |
|---|
| 852 | return [[], str] |
|---|
| 853 | end if |
|---|
| 854 | offs = offset("<?", str) |
|---|
| 855 | end repeat |
|---|
| 856 | |
|---|
| 857 | -- doctype: |
|---|
| 858 | offs = offset("<!Doctype", str) |
|---|
| 859 | repeat while offs |
|---|
| 860 | ende = offset(">", str.char[offs .. str.length]) |
|---|
| 861 | if ende > 0 then |
|---|
| 862 | delete char offs to (ende + offs - 1) of str |
|---|
| 863 | else |
|---|
| 864 | return [[], str] |
|---|
| 865 | end if |
|---|
| 866 | offs = offset("<!Doctype", str) |
|---|
| 867 | end repeat |
|---|
| 868 | |
|---|
| 869 | -- comments |
|---|
| 870 | offs = offset("<!--", str) |
|---|
| 871 | repeat while offs |
|---|
| 872 | ende = offset("-->", str) |
|---|
| 873 | if ende > 0 then |
|---|
| 874 | delete char offs to (ende + 2) of str |
|---|
| 875 | else |
|---|
| 876 | return [[], str] |
|---|
| 877 | end if |
|---|
| 878 | offs = offset("<!--", str) |
|---|
| 879 | end repeat |
|---|
| 880 | |
|---|
| 881 | return str |
|---|
| 882 | end |
|---|
| 883 | |
|---|
| 884 | -- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
|---|
| 885 | |
|---|
| 886 | on mEscapeSpecialChars me, str |
|---|
| 887 | |
|---|
| 888 | val = mReplaceAllGT(me, string(str), "&", "&") |
|---|
| 889 | val = mReplaceAllGT(me, val, "<", "<") |
|---|
| 890 | val = mReplaceAllGT(me, val, ">", ">") |
|---|
| 891 | val = mReplaceAllGT(me, val, "'", "'") |
|---|
| 892 | val = mReplaceAllGT(me, val, QUOTE, """) |
|---|
| 893 | |
|---|
| 894 | return val |
|---|
| 895 | |
|---|
| 896 | end |
|---|
| 897 | |
|---|
| 898 | -- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
|---|
| 899 | |
|---|
| 900 | on mUnEscapeSpecialChars me, str |
|---|
| 901 | |
|---|
| 902 | val = mReplaceAllGT(me, string(str), "<", "<") |
|---|
| 903 | val = mReplaceAllGT(me, val, ">", ">") |
|---|
| 904 | val = mReplaceAllGT(me, val, "'", "'") |
|---|
| 905 | val = mReplaceAllGT(me, val, """, QUOTE) |
|---|
| 906 | val = mReplaceAllGT(me, val, "&", "&") |
|---|
| 907 | |
|---|
| 908 | return val |
|---|
| 909 | end |
|---|
| 910 | |
|---|
| 911 | -- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
|---|
| 912 | |
|---|
| 913 | on mReplaceAllGT me, srcText, fromChunk, toChunk |
|---|
| 914 | if the runmode contains "plugin" then return mReplaceChunkGT(me, srcText, fromChunk, toChunk) |
|---|
| 915 | if mCheckForRegEx(me) = 0 then return mReplaceChunkGT(me, srcText, fromChunk, toChunk) |
|---|
| 916 | |
|---|
| 917 | -- mit pregEx() |
|---|
| 918 | retlist = [srcText] |
|---|
| 919 | PRegEx_Replace(retlist, PRegEx_QuoteMeta(fromChunk) , "ig", PRegEx_QuoteMeta(toChunk)) |
|---|
| 920 | |
|---|
| 921 | return retlist[1] |
|---|
| 922 | end |
|---|
| 923 | |
|---|
| 924 | -- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
|---|
| 925 | |
|---|
| 926 | -- mit offset() |
|---|
| 927 | on mReplaceChunkGT me, srcText, fromChunk, toChunk |
|---|
| 928 | |
|---|
| 929 | stelle = offset(fromChunk, srcText) |
|---|
| 930 | |
|---|
| 931 | offs = 0 |
|---|
| 932 | if stelle then |
|---|
| 933 | |
|---|
| 934 | newtext = "" |
|---|
| 935 | repeat while stelle |
|---|
| 936 | if stelle > 1 then put char 1 to (stelle - 1) of srcText after newtext |
|---|
| 937 | put toChunk after newtext |
|---|
| 938 | delete char 1 to (stelle + fromChunk.length - 1) of srcText |
|---|
| 939 | stelle = offset(fromChunk, srcText) |
|---|
| 940 | if stelle = 0 then put srcText after newtext |
|---|
| 941 | end repeat |
|---|
| 942 | |
|---|
| 943 | else |
|---|
| 944 | return srcText |
|---|
| 945 | end if |
|---|
| 946 | |
|---|
| 947 | return newtext |
|---|
| 948 | end |
|---|
| 949 | |
|---|
| 950 | -- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
|---|
| 951 | |
|---|
| 952 | property pRegExtra |
|---|
| 953 | |
|---|
| 954 | on mCheckForRegEx me |
|---|
| 955 | if voidP(pRegExtra) then |
|---|
| 956 | pRegExtra = 0 |
|---|
| 957 | repeat with n = the number of xtras down to 1 |
|---|
| 958 | if (the name of xtra n = "PRegEx") then |
|---|
| 959 | pRegExtra = 1 |
|---|
| 960 | exit repeat |
|---|
| 961 | end if |
|---|
| 962 | end repeat |
|---|
| 963 | end if |
|---|
| 964 | return pRegExtra |
|---|
| 965 | end |
|---|
| 966 | |
|---|
| 967 | |
|---|
| 968 | -- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
|---|
| 969 | |
|---|
| 970 | on mConvertXMLPropList me, inputlist, convertValues, dontEscapeSpecialChars |
|---|
| 971 | retlist = [:] |
|---|
| 972 | anz = count(inputlist) |
|---|
| 973 | repeat with n = 1 to anz |
|---|
| 974 | val = inputlist[n].getaprop(#child) |
|---|
| 975 | |
|---|
| 976 | if listP(val) then |
|---|
| 977 | |
|---|
| 978 | if n = 1 then |
|---|
| 979 | propname = inputlist[n].getaprop(#name) |
|---|
| 980 | if offset("item", propname) = 1 then |
|---|
| 981 | retlist = [] |
|---|
| 982 | end if |
|---|
| 983 | end if |
|---|
| 984 | |
|---|
| 985 | if count(val) then |
|---|
| 986 | if ilk(retlist) = #proplist then |
|---|
| 987 | retlist.addProp(symbol(inputlist[n].getaprop(#name)), mConvertXMLPropList(me, val, convertValues, dontEscapeSpecialChars)) |
|---|
| 988 | else |
|---|
| 989 | retlist.add(mConvertXMLPropList(me, val, convertValues, dontEscapeSpecialChars)) |
|---|
| 990 | end if |
|---|
| 991 | else |
|---|
| 992 | val = inputlist[n].getaprop(#chardata) |
|---|
| 993 | |
|---|
| 994 | attr = "" |
|---|
| 995 | attrLi = inputlist[n].getaprop(#attributes) |
|---|
| 996 | if ilk(attrLi) = #proplist then |
|---|
| 997 | attr = string(attrLi.getaprop(#ilk)) |
|---|
| 998 | end if |
|---|
| 999 | |
|---|
| 1000 | |
|---|
| 1001 | |
|---|
| 1002 | if length(attr) > 0 then |
|---|
| 1003 | |
|---|
| 1004 | attr = symbol(attr) |
|---|
| 1005 | case attr of |
|---|
| 1006 | #string: |
|---|
| 1007 | |
|---|
| 1008 | -- unescape <>&'" |
|---|
| 1009 | if dontEscapeSpecialChars <> 1 then val = mUnEscapeSpecialChars(me, val) |
|---|
| 1010 | |
|---|
| 1011 | #integer: |
|---|
| 1012 | val = integer(val) |
|---|
| 1013 | #float: |
|---|
| 1014 | val = float(val) |
|---|
| 1015 | otherwise |
|---|
| 1016 | v2 = value(val) |
|---|
| 1017 | if ilk(v2) <> attr then val = void |
|---|
| 1018 | |
|---|
| 1019 | end case |
|---|
| 1020 | |
|---|
| 1021 | else |
|---|
| 1022 | |
|---|
| 1023 | -- simple case, only check for integer and float values: |
|---|
| 1024 | if convertValues = 1 then |
|---|
| 1025 | |
|---|
| 1026 | v2 = mConvertToNumber(me, val) |
|---|
| 1027 | if voidP(v2) then |
|---|
| 1028 | |
|---|
| 1029 | -- unescape <>&'" |
|---|
| 1030 | if dontEscapeSpecialChars <> 1 then val = mUnEscapeSpecialChars(me, val) |
|---|
| 1031 | |
|---|
| 1032 | else |
|---|
| 1033 | val = v2 |
|---|
| 1034 | end if |
|---|
| 1035 | |
|---|
| 1036 | |
|---|
| 1037 | -- slower case, check for hex color values and value(): |
|---|
| 1038 | else if convertValues = 2 then |
|---|
| 1039 | |
|---|
| 1040 | v2 = mFindIlk(me, val) |
|---|
| 1041 | if voidP(v2) then |
|---|
| 1042 | |
|---|
| 1043 | -- unescape <>&'" |
|---|
| 1044 | if dontEscapeSpecialChars <> 1 then val = mUnEscapeSpecialChars(me, val) |
|---|
| 1045 | |
|---|
| 1046 | else |
|---|
| 1047 | val = v2 |
|---|
| 1048 | end if |
|---|
| 1049 | |
|---|
| 1050 | |
|---|
| 1051 | else |
|---|
| 1052 | |
|---|
| 1053 | -- unescape <>&'" |
|---|
| 1054 | if dontEscapeSpecialChars <> 1 then val = mUnEscapeSpecialChars(me, val) |
|---|
| 1055 | |
|---|
| 1056 | |
|---|
| 1057 | end if |
|---|
| 1058 | |
|---|
| 1059 | end if -- attr found |
|---|
| 1060 | |
|---|
| 1061 | |
|---|
| 1062 | |
|---|
| 1063 | -- if ((not(voidP(v2))) and string(v2).length) then val = v2 |
|---|
| 1064 | |
|---|
| 1065 | if ilk(retlist) = #proplist then |
|---|
| 1066 | retlist.addProp(symbol(inputlist[n].getaprop(#name)), val) |
|---|
| 1067 | else |
|---|
| 1068 | retlist.add(val) |
|---|
| 1069 | end if |
|---|
| 1070 | |
|---|
| 1071 | end if |
|---|
| 1072 | |
|---|
| 1073 | end if |
|---|
| 1074 | |
|---|
| 1075 | end repeat |
|---|
| 1076 | |
|---|
| 1077 | return retlist |
|---|
| 1078 | end |
|---|
| 1079 | |
|---|
| 1080 | |
|---|
| 1081 | -- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
|---|
| 1082 | |
|---|
| 1083 | on mParseExcelXML me, theText |
|---|
| 1084 | ----------------------------------- |
|---|
| 1085 | -- ACTION: Read and convert an excel xml file into a lingo property list |
|---|
| 1086 | -- INPUT: <theText> ; string ; required => xml formatted string |
|---|
| 1087 | -- RETURNS: property list |
|---|
| 1088 | -- EXAMPLE: plist = new(script "PseudoXMLPS").mParseExcelXML(xscr(#FileIOFunktionen).mGetTextFromFile()) |
|---|
| 1089 | ----------------------------------- |
|---|
| 1090 | |
|---|
| 1091 | ms = the milliseconds |
|---|
| 1092 | li = [] |
|---|
| 1093 | xmlp = new(xtra "xmlparser") |
|---|
| 1094 | xmlp.parseString(theText) |
|---|
| 1095 | if voidP(xmlp.getError()) then |
|---|
| 1096 | xmlList = xmlp.makeList() |
|---|
| 1097 | if listP(xmlList) then |
|---|
| 1098 | if count(xmlList) > 0 then |
|---|
| 1099 | xmlList = xmlList[1] |
|---|
| 1100 | if ilk(xmlList) = #proplist then |
|---|
| 1101 | xmlList = xmlList.getaprop("Workbook") |
|---|
| 1102 | if ilk(xmlList) = #proplist then |
|---|
| 1103 | xmlList = xmlList.getaprop("Worksheet") |
|---|
| 1104 | if ilk(xmlList) = #proplist then |
|---|
| 1105 | xmlList = xmlList.getaprop("Table") |
|---|
| 1106 | if listP(xmlList) then |
|---|
| 1107 | rowCnt = count(xmlList) |
|---|
| 1108 | repeat with n = 2 to rowCnt |
|---|
| 1109 | thisRow = [] |
|---|
| 1110 | li.add(thisRow) |
|---|
| 1111 | currRow = xmlList[n] |
|---|
| 1112 | if listP(currRow) then |
|---|
| 1113 | cellCnt = count(currRow) |
|---|
| 1114 | repeat with m = 2 to cellCnt |
|---|
| 1115 | thisCell = currRow[m].getaprop("Data") |
|---|
| 1116 | if ilk(thisCell) = #proplist then |
|---|
| 1117 | dertyp = thisCell.getaprop("!ATTRIBUTES") |
|---|
| 1118 | if ilk(dertyp) = #proplist then dertyp = dertyp.getaprop("ss:Type") |
|---|
| 1119 | case dertyp of |
|---|
| 1120 | "Number": |
|---|
| 1121 | thisRow.add(float(thisCell.getaprop("!CHARDATA"))) |
|---|
| 1122 | otherwise |
|---|
| 1123 | thisRow.add(thisCell.getaprop("!CHARDATA")) |
|---|
| 1124 | end case |
|---|
| 1125 | |
|---|
| 1126 | else |
|---|
| 1127 | put "mParseExcelXML: Row "&n&" Cell "&m&" is not a property list" |
|---|
| 1128 | end if -- if ilk(thisCell) = #proplist then |
|---|
| 1129 | |
|---|
| 1130 | end repeat -- repeat through cells |
|---|
| 1131 | |
|---|
| 1132 | else |
|---|
| 1133 | put "mParseExcelXML: Row "&n&" is not a list" |
|---|
| 1134 | end if -- if listP(currRow) then |
|---|
| 1135 | |
|---|
| 1136 | end repeat -- repeat through rows |
|---|
| 1137 | |
|---|
| 1138 | else |
|---|
| 1139 | put "mParseExcelXML: Table not found" |
|---|
| 1140 | end if -- if listP(xmlList) then |
|---|
| 1141 | |
|---|
| 1142 | else |
|---|
| 1143 | put "mParseExcelXML: Worksheet not found" |
|---|
| 1144 | end if -- if ilk(xmlList) = #proplist then |
|---|
| 1145 | |
|---|
| 1146 | else |
|---|
| 1147 | put "mParseExcelXML: Workbook not found" |
|---|
| 1148 | end if -- if ilk(xmlList) = #proplist then |
|---|
| 1149 | |
|---|
| 1150 | else |
|---|
| 1151 | put "mParseExcelXML: ROOT is not a property list" |
|---|
| 1152 | end if --if ilk(xmlList) = #proplist then |
|---|
| 1153 | |
|---|
| 1154 | else |
|---|
| 1155 | put "mParseExcelXML: Xml parser makelist() returned empty list" |
|---|
| 1156 | end if -- if count(xmlList) > 0 then |
|---|
| 1157 | |
|---|
| 1158 | else |
|---|
| 1159 | put "mParseExcelXML: Xml parser makelist() failed" |
|---|
| 1160 | end if -- if listP(xmlList) then |
|---|
| 1161 | |
|---|
| 1162 | else |
|---|
| 1163 | put "mParseExcelXML: Xml parser error: "&xmlp.getError() |
|---|
| 1164 | end if -- if voidP(xmlp.getError()) then |
|---|
| 1165 | |
|---|
| 1166 | xmlp = 0 |
|---|
| 1167 | -- put the milliseconds - ms |
|---|
| 1168 | return li |
|---|
| 1169 | end |
|---|
| 1170 | |
|---|
| 1171 | -- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
|---|
| 1172 | -- read apple style plist file |
|---|
| 1173 | |
|---|
| 1174 | on mReadPList me, pfad |
|---|
| 1175 | ----------------------------------- |
|---|
| 1176 | -- ACTION: Read and convrt an apple style plist into a lingo style property list from file |
|---|
| 1177 | -- INPUT: <pfad> ; string ; full pathname to plist file. This is optional, if it is void or "" a file selection dialog is displayed |
|---|
| 1178 | -- RETURNS: property list |
|---|
| 1179 | -- EXAMPLE: plist = new(script "PseudoXMLPS").mReadPList() |
|---|
| 1180 | ----------------------------------- |
|---|
| 1181 | |
|---|
| 1182 | str = "" |
|---|
| 1183 | |
|---|
| 1184 | if string(pfad) starts "/" then |
|---|
| 1185 | if mCheckShellXtra(me) <> 1 then return ["You need the Shell xtra to convert binary plist files"] |
|---|
| 1186 | str = string(shell_cmd("cat ""E&pfad"E)) |
|---|
| 1187 | else |
|---|
| 1188 | fio = new(xtra "fileio") |
|---|
| 1189 | if (voidP(pfad) or (pfad = "")) then pfad = fio.displayOpen() |
|---|
| 1190 | |
|---|
| 1191 | if ilk(pfad) <> #string then return [] |
|---|
| 1192 | if not(pfad.length) then return [] |
|---|
| 1193 | |
|---|
| 1194 | fio.openFile(pfad, 1) |
|---|
| 1195 | if fio.status() <> 0 then |
|---|
| 1196 | retval = [fio.error(fio.status())] |
|---|
| 1197 | fio = void |
|---|
| 1198 | return retval |
|---|
| 1199 | end if |
|---|
| 1200 | |
|---|
| 1201 | str = fio.readFile() |
|---|
| 1202 | fio.closeFile() |
|---|
| 1203 | fio = void |
|---|
| 1204 | end if |
|---|
| 1205 | |
|---|
| 1206 | |
|---|
| 1207 | if not(str starts "<?xml") then -- since 10.4 plist files are no longer in raw text format, we need to convert the binary file |
|---|
| 1208 | |
|---|
| 1209 | if not(pfad starts "/") then |
|---|
| 1210 | -- convert to unix path |
|---|
| 1211 | offs = offset(":", pfad) |
|---|
| 1212 | repeat while offs > 0 |
|---|
| 1213 | put "/" into char offs of pfad |
|---|
| 1214 | offs = offset(":", pfad) |
|---|
| 1215 | end repeat |
|---|
| 1216 | put "/Volumes/" before pfad |
|---|
| 1217 | end if |
|---|
| 1218 | |
|---|
| 1219 | if mCheckShellXtra(me) <> 1 then return ["You need the Shell xtra to convert binary plist files"] |
|---|
| 1220 | |
|---|
| 1221 | shell_cmd("plutil -convert xml1 -o /var/tmp/tempplist ""E&pfad"E) |
|---|
| 1222 | str = shell_cmd("cat /var/tmp/tempplist") |
|---|
| 1223 | end if |
|---|
| 1224 | |
|---|
| 1225 | |
|---|
| 1226 | return mGetListFromPListString(me, str) |
|---|
| 1227 | |
|---|
| 1228 | end |
|---|
| 1229 | |
|---|
| 1230 | -- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
|---|
| 1231 | -- this is required to convert a 10.4 style binary plist file to xml: |
|---|
| 1232 | |
|---|
| 1233 | property pShellXtraPresent |
|---|
| 1234 | |
|---|
| 1235 | on mCheckShellXtra me |
|---|
| 1236 | if voidP(pShellXtraPresent) then |
|---|
| 1237 | pShellXtraPresent = 0 |
|---|
| 1238 | repeat with n = the number of xtras down to 1 |
|---|
| 1239 | if (the name of xtra n = "Shell") then |
|---|
| 1240 | pShellXtraPresent = 1 |
|---|
| 1241 | exit repeat |
|---|
| 1242 | end if |
|---|
| 1243 | end repeat |
|---|
| 1244 | end if |
|---|
| 1245 | return pShellXtraPresent |
|---|
| 1246 | end |
|---|
| 1247 | |
|---|
| 1248 | -- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
|---|
| 1249 | -- read apple style plist file |
|---|
| 1250 | |
|---|
| 1251 | on mGetListFromPListString me, str |
|---|
| 1252 | return mConvertKeyList(me, mGetListFromXMLString(me, str, 0)) |
|---|
| 1253 | end |
|---|
| 1254 | |
|---|
| 1255 | |
|---|
| 1256 | -- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
|---|
| 1257 | -- convert apple style plist |
|---|
| 1258 | |
|---|
| 1259 | on mConvertKeyList me, inputlist |
|---|
| 1260 | if ilk(inputlist) <> #proplist then return inputlist |
|---|
| 1261 | retlist = [:] |
|---|
| 1262 | cnt = count(inputlist) |
|---|
| 1263 | |
|---|
| 1264 | repeat with n = 1 to cnt |
|---|
| 1265 | if (inputlist.getpropAt(n) = #key) then |
|---|
| 1266 | prop = inputlist[n] |
|---|
| 1267 | n = n + 1 |
|---|
| 1268 | theIlk = inputlist.getpropAt(n) |
|---|
| 1269 | retlist.addProp(prop, mGetKeyListValue(me, theIlk, inputlist[n])) |
|---|
| 1270 | else |
|---|
| 1271 | retlist.addProp(#dict, mConvertKeyList(me, inputlist[n])) |
|---|
| 1272 | end if |
|---|
| 1273 | end repeat |
|---|
| 1274 | |
|---|
| 1275 | return retlist |
|---|
| 1276 | |
|---|
| 1277 | end |
|---|
| 1278 | |
|---|
| 1279 | -- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
|---|
| 1280 | |
|---|
| 1281 | on mGetKeyListValue me, theIlk, theValue |
|---|
| 1282 | case theIlk of |
|---|
| 1283 | #array: |
|---|
| 1284 | li = [] |
|---|
| 1285 | if ilk(theValue) = #proplist then |
|---|
| 1286 | cnt = count(theValue) |
|---|
| 1287 | repeat with n = 1 to cnt |
|---|
| 1288 | li.add(mGetKeyListValue(me, theValue.getPropAt(n), theValue[n])) |
|---|
| 1289 | end repeat |
|---|
| 1290 | end if |
|---|
| 1291 | return li |
|---|
| 1292 | #dict: |
|---|
| 1293 | return mConvertKeyList(me, theValue) |
|---|
| 1294 | #real: |
|---|
| 1295 | return float(theValue) |
|---|
| 1296 | #integer: |
|---|
| 1297 | return integer(theValue) |
|---|
| 1298 | #false: |
|---|
| 1299 | return 0 |
|---|
| 1300 | #true: |
|---|
| 1301 | return 1 |
|---|
| 1302 | otherwise |
|---|
| 1303 | return string(theValue) |
|---|
| 1304 | end case |
|---|
| 1305 | end |
|---|
| 1306 | |
|---|
| 1307 | |
|---|
| 1308 | -- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
|---|
| 1309 | -- fontmapping |
|---|
| 1310 | -- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
|---|
| 1311 | |
|---|
| 1312 | on mMapCharCodes me, str, whichDirection |
|---|
| 1313 | |
|---|
| 1314 | if mCheckForRegEx(me) = 1 then |
|---|
| 1315 | return mMapCharsCodesP(me, str, whichDirection) |
|---|
| 1316 | end if |
|---|
| 1317 | |
|---|
| 1318 | replLi = mGetCharMapList(me) |
|---|
| 1319 | |
|---|
| 1320 | if whichDirection = #Win2Mac then |
|---|
| 1321 | indTo = 1 |
|---|
| 1322 | indFrom = 2 |
|---|
| 1323 | else |
|---|
| 1324 | indTo = 2 |
|---|
| 1325 | indFrom = 1 |
|---|
| 1326 | end if |
|---|
| 1327 | |
|---|
| 1328 | if getVersionNumber(me) > 10.99 then |
|---|
| 1329 | -- director 11 will have unicode numbers for the chars |
|---|
| 1330 | indFrom = 3 |
|---|
| 1331 | end if |
|---|
| 1332 | |
|---|
| 1333 | |
|---|
| 1334 | newStr = str |
|---|
| 1335 | repeat with repl in replLi |
|---|
| 1336 | tstr = str |
|---|
| 1337 | vers = 0 |
|---|
| 1338 | searchChar = numToChar(repl[indFrom]) |
|---|
| 1339 | replaceChar = numToChar(repl[indTo]) |
|---|
| 1340 | offs = offset(searchChar, tstr) |
|---|
| 1341 | repeat while offs > 0 |
|---|
| 1342 | ctn = charToNum(char offs of tstr) |
|---|
| 1343 | delete char 1 to offs of tstr |
|---|
| 1344 | vers = vers + offs |
|---|
| 1345 | if ctn = repl[indFrom] then |
|---|
| 1346 | put replaceChar into char vers of newStr |
|---|
| 1347 | end if |
|---|
| 1348 | offs = offset(searchChar, tstr) |
|---|
| 1349 | end repeat |
|---|
| 1350 | end repeat |
|---|
| 1351 | |
|---|
| 1352 | zehn = numToChar(10) |
|---|
| 1353 | offs = offset(zehn, newStr) |
|---|
| 1354 | repeat while offs > 0 |
|---|
| 1355 | delete char offs of newStr |
|---|
| 1356 | offs = offset(zehn, newStr) |
|---|
| 1357 | end repeat |
|---|
| 1358 | |
|---|
| 1359 | return newStr |
|---|
| 1360 | end |
|---|
| 1361 | |
|---|
| 1362 | -- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
|---|
| 1363 | -- using pregex: |
|---|
| 1364 | |
|---|
| 1365 | on mMapCharsCodesP me, str, whichDirection |
|---|
| 1366 | strli = [str] |
|---|
| 1367 | li = mGetPregTranslateStrings(me) |
|---|
| 1368 | |
|---|
| 1369 | if whichDirection = #Win2Mac then |
|---|
| 1370 | pregex_translate(strli, li[2], li[1]) |
|---|
| 1371 | |
|---|
| 1372 | PRegEx_Replace(strli, "\" & numToChar(10), "g", "") |
|---|
| 1373 | |
|---|
| 1374 | else |
|---|
| 1375 | pregex_translate(strli, li[1], li[2]) |
|---|
| 1376 | |
|---|
| 1377 | end if |
|---|
| 1378 | |
|---|
| 1379 | return strli[1] |
|---|
| 1380 | end |
|---|
| 1381 | |
|---|
| 1382 | -- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
|---|
| 1383 | |
|---|
| 1384 | on mGetPregTranslateStrings me |
|---|
| 1385 | |
|---|
| 1386 | replLi = mGetCharMapList(me) |
|---|
| 1387 | fromStr = "" |
|---|
| 1388 | toStr = "" |
|---|
| 1389 | |
|---|
| 1390 | if getVersionNumber(me) > 10.99 then |
|---|
| 1391 | -- director 11 will have unicode numbers for the chars |
|---|
| 1392 | fromIndex = 3 |
|---|
| 1393 | else |
|---|
| 1394 | fromIndex = 1 |
|---|
| 1395 | end if |
|---|
| 1396 | |
|---|
| 1397 | repeat with repl in replLi |
|---|
| 1398 | put numToChar(repl[fromIndex]) after fromStr |
|---|
| 1399 | put numToChar(repl[2]) after toStr |
|---|
| 1400 | end repeat |
|---|
| 1401 | |
|---|
| 1402 | return [fromStr, toStr] |
|---|
| 1403 | |
|---|
| 1404 | end |
|---|
| 1405 | |
|---|
| 1406 | -- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
|---|
| 1407 | |
|---|
| 1408 | on mGetCharMapList me |
|---|
| 1409 | li = [] |
|---|
| 1410 | li.add([128, 196, 402]) |
|---|
| 1411 | li.add([129, 197, 8776]) |
|---|
| 1412 | li.add([130, 199, 171]) |
|---|
| 1413 | li.add([131, 201, 8230]) |
|---|
| 1414 | li.add([132, 209, 8212]) |
|---|
| 1415 | li.add([133, 214, 247]) |
|---|
| 1416 | li.add([134, 220, 8249]) |
|---|
| 1417 | li.add([135, 225, 183]) |
|---|
| 1418 | li.add([136, 224, 8225]) |
|---|
| 1419 | li.add([137, 226, 8218]) |
|---|
| 1420 | li.add([138, 228, 8240]) |
|---|
| 1421 | li.add([139, 227, 8222]) |
|---|
| 1422 | li.add([140, 229, 194]) |
|---|
| 1423 | li.add([141, 231, 193]) |
|---|
| 1424 | li.add([142, 233, 200]) |
|---|
| 1425 | li.add([143, 232, 203]) |
|---|
| 1426 | li.add([144, 234, 205]) |
|---|
| 1427 | li.add([145, 235, 206]) |
|---|
| 1428 | li.add([146, 237, 204]) |
|---|
| 1429 | li.add([147, 236, 207]) |
|---|
| 1430 | li.add([148, 238, 211]) |
|---|
| 1431 | li.add([149, 239, 212]) |
|---|
| 1432 | li.add([150, 241, 210]) |
|---|
| 1433 | li.add([151, 243, 219]) |
|---|
| 1434 | li.add([152, 242, 218]) |
|---|
| 1435 | li.add([153, 244, 217]) |
|---|
| 1436 | li.add([154, 246, 710]) |
|---|
| 1437 | li.add([155, 245, 305]) |
|---|
| 1438 | li.add([156, 250, 729]) |
|---|
| 1439 | li.add([157, 249, 728]) |
|---|
| 1440 | li.add([158, 251, 730]) |
|---|
| 1441 | li.add([159, 252, 184]) |
|---|
| 1442 | li.add([160, 134, 220]) |
|---|
| 1443 | li.add([161, 176, 8734]) |
|---|
| 1444 | li.add([164, 167, 223]) |
|---|
| 1445 | li.add([165, 149, 239]) |
|---|
| 1446 | li.add([166, 182, 8706]) |
|---|
| 1447 | li.add([167, 223, 64258]) |
|---|
| 1448 | li.add([168, 174, 198]) |
|---|
| 1449 | li.add([170, 153, 244]) |
|---|
| 1450 | li.add([171, 180, 165]) |
|---|
| 1451 | li.add([172, 168, 174]) |
|---|
| 1452 | li.add([173, 141, 231]) |
|---|
| 1453 | li.add([174, 198, 8710]) |
|---|
| 1454 | li.add([175, 216, 255]) |
|---|
| 1455 | li.add([176, 144, 234]) |
|---|
| 1456 | li.add([178, 143, 232]) |
|---|
| 1457 | li.add([179, 142, 233]) |
|---|
| 1458 | li.add([180, 165, 8226]) |
|---|
| 1459 | li.add([182, 240, 63743]) |
|---|
| 1460 | li.add([183, 221, 8250]) |
|---|
| 1461 | li.add([184, 222, 64257]) |
|---|
| 1462 | li.add([185, 254, 731]) |
|---|
| 1463 | li.add([186, 138, 228]) |
|---|
| 1464 | li.add([187, 170, 8482]) |
|---|
| 1465 | li.add([188, 186, 8747]) |
|---|
| 1466 | li.add([189, 253, 733]) |
|---|
| 1467 | li.add([190, 230, 202]) |
|---|
| 1468 | li.add([191, 248, 175]) |
|---|
| 1469 | li.add([192, 191, 248]) |
|---|
| 1470 | li.add([193, 161, 176]) |
|---|
| 1471 | li.add([194, 172, 168]) |
|---|
| 1472 | li.add([195, 175, 216]) |
|---|
| 1473 | li.add([196, 131, 201]) |
|---|
| 1474 | li.add([197, 188, 186]) |
|---|
| 1475 | li.add([198, 208, 8211]) |
|---|
| 1476 | li.add([199, 171, 180]) |
|---|
| 1477 | li.add([200, 187, 170]) |
|---|
| 1478 | li.add([201, 133, 214]) |
|---|
| 1479 | li.add([202, 160, 8224]) |
|---|
| 1480 | li.add([203, 192, 191]) |
|---|
| 1481 | li.add([204, 195, 8730]) |
|---|
| 1482 | li.add([205, 213, 8217]) |
|---|
| 1483 | li.add([206, 140, 229]) |
|---|
| 1484 | li.add([207, 156, 250]) |
|---|
| 1485 | li.add([208, 173, 8800]) |
|---|
| 1486 | li.add([209, 151, 243]) |
|---|
| 1487 | li.add([210, 147, 236]) |
|---|
| 1488 | li.add([211, 148, 238]) |
|---|
| 1489 | li.add([212, 145, 235]) |
|---|
| 1490 | li.add([213, 146, 237]) |
|---|
| 1491 | li.add([214, 247, 732]) |
|---|
| 1492 | li.add([216, 255, 711]) |
|---|
| 1493 | li.add([217, 159, 252]) |
|---|
| 1494 | li.add([218, 158, 251]) |
|---|
| 1495 | li.add([219, 128, 196]) |
|---|
| 1496 | li.add([220, 139, 227]) |
|---|
| 1497 | li.add([221, 155, 245]) |
|---|
| 1498 | li.add([222, 128, 196]) |
|---|
| 1499 | li.add([223, 129, 197]) |
|---|
| 1500 | li.add([224, 135, 225]) |
|---|
| 1501 | li.add([225, 183, 8721]) |
|---|
| 1502 | li.add([226, 130, 199]) |
|---|
| 1503 | li.add([227, 132, 209]) |
|---|
| 1504 | li.add([228, 137, 226]) |
|---|
| 1505 | li.add([229, 194, 172]) |
|---|
| 1506 | li.add([230, 202, 160]) |
|---|
| 1507 | li.add([231, 193, 161]) |
|---|
| 1508 | li.add([232, 203, 192]) |
|---|
| 1509 | li.add([233, 200, 187]) |
|---|
| 1510 | li.add([234, 205, 213]) |
|---|
| 1511 | li.add([235, 206, 338]) |
|---|
| 1512 | li.add([236, 207, 339]) |
|---|
| 1513 | li.add([237, 204, 195]) |
|---|
| 1514 | li.add([238, 211, 8221]) |
|---|
| 1515 | li.add([239, 212, 8216]) |
|---|
| 1516 | li.add([240, 157, 249]) |
|---|
| 1517 | li.add([241, 210, 8220]) |
|---|
| 1518 | li.add([242, 218, 8260]) |
|---|
| 1519 | li.add([243, 219, 8364]) |
|---|
| 1520 | li.add([244, 217, 376]) |
|---|
| 1521 | li.add([245, 166, 182]) |
|---|
| 1522 | li.add([246, 136, 224]) |
|---|
| 1523 | li.add([247, 152, 242]) |
|---|
| 1524 | li.add([248, 150, 241]) |
|---|
| 1525 | li.add([249, 154, 246]) |
|---|
| 1526 | li.add([250, 178, 8804]) |
|---|
| 1527 | li.add([251, 190, 230]) |
|---|
| 1528 | li.add([252, 184, 8719]) |
|---|
| 1529 | li.add([253, 189, 937]) |
|---|
| 1530 | li.add([254, 179, 8805]) |
|---|
| 1531 | li.add([255, 185, 960]) |
|---|
| 1532 | return li |
|---|
| 1533 | end |
|---|
| 1534 | |
|---|
| 1535 | -- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
|---|
| 1536 | |
|---|
| 1537 | on getVersionNumber me |
|---|
| 1538 | if voidP(pVersionNumber) then |
|---|
| 1539 | pVersionNumber = getFloatVersionNumber(me, the productVersion) |
|---|
| 1540 | end if |
|---|
| 1541 | return pVersionNumber |
|---|
| 1542 | end |
|---|
| 1543 | |
|---|
| 1544 | -- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
|---|
| 1545 | |
|---|
| 1546 | on getFloatVersionNumber me, prodVers |
|---|
| 1547 | offs = offset(".", prodVers) |
|---|
| 1548 | if offs > 0 then |
|---|
| 1549 | intVers = char 1 to offs of prodVers |
|---|
| 1550 | delete char 1 to offs of prodVers |
|---|
| 1551 | else |
|---|
| 1552 | intVers = "" |
|---|
| 1553 | end if |
|---|
| 1554 | cnt = length(prodVers) |
|---|
| 1555 | repeat with n = 1 to cnt |
|---|
| 1556 | c = prodVers.char[n] |
|---|
| 1557 | if integerP(integer(c)) then |
|---|
| 1558 | put c after intVers |
|---|
| 1559 | else if c <> "." then |
|---|
| 1560 | exit repeat |
|---|
| 1561 | end if |
|---|
| 1562 | end repeat |
|---|
| 1563 | return value(intVers) |
|---|
| 1564 | end |
|---|