[Script] [Util] Chem String Functions Library v. 2.81 [18 Aug 2007]
Moderators: Moderators for English X Forum, Scripting / Modding Moderators
[Script] [Util] Chem String Functions Library v. 2.81 [18 Aug 2007]
################################################################################
Script : Chem String Functions Library
Author : Chem
E-mail : chemodun@gmail.com
Web : http://www[dot]elite-games[dot]ru/x3/
Version: 2.81
Desc. :Provide some functions for manipulate with string,
based on their displayed width
################################################################################
_____________
Download:
Spk version
Zip version
History :
2.81
-added new function 'length', it return displayed width of string. If second parameter are [TRUE] - then length will be returned in spaces, otherwise - in pseudosymbols
2.78
-fixed error in functions 'fill.spaces', if used possibility read string from file - it's work incorrectly (Big thanks to X-Freak Cartman [KBG])
-used new version of .spk
2.76
-fixed error with aligning in functions 'fill.spaces', where aling = [FALSE] (Was - filled left, but must be - filled right)
2.75
- fixed error in definition aligining in functions 'fill.spaces', 'fill.sum.to.string', 'fill.number.to.string'
- added new function 'sprintf'
- functions 'fill.spaces', 'sprintf', 'split.string.by.delim' can use as parameters string, and integer vaules( for reading strings from text files)
- all functions corretly work with 2 bytes symbols (like Russian)
- if string are longer then must be displayet - it's truncated
2.09 - first public release
_____________
Installation :
Install via Cycrow Script Manager (Plugin Manager)
_____________
Use:
Libraries has two script files:
setup.lib.chem.string.xml - this file prepare special array for filling string by space.
Script doesn't have any parameters.
lib.chem.strings.xml - main library script.
Script has 6 parameters:
mode (Work Mode) - for defining which function called from library
Arg1..Arg5 - for setting functions parameters
Now in version 2.81 library provide 8 functions:
1. split.string.by.delim
Arg1 - string-delimeter - string, or string from text file by page id Arg1 and text id Arg2
Arg2 - string-source - string, or string from text file by page id Arg2(or Arg3) and text id Arg3 (or $Arg4)
Arg3 - max count parts of source string (if null - max count = 99)
return - array of found parts of source string
It's function can split source string (first) by delimeter (second).
You can set maximum count of parts for splitting (Arg3), i.e. if source has more then one occurrence of delimiter , but you set Arg3 = 2 - function will return array with only 2 elements, first - source string before first occurrence of Arg1 in Arg2, and second - all source after this first occurrence.
2.'fill.spaces' - you can create string with correct displayed width in player logbook, i.e. after using this function on, for example, strings "this is long string" and "small string", they will be filled by spaces up to they width in pixels (not symbols) will be equal.
Arg1 - source string, or string from text file by page id Arg1 and text id Arg2
Arg2 or Arg3- max len (in spaces, i.e. count of sybols " ")
Arg3 or Arg4- fill
if bool
TRUE - fill left (align right)
FALSE - fill right (align left)
if string
'-' - align left
'=' - align center
'+' - align right
It's function will fill source string by spaces based not on count of symbols in string, but on their summary width on screen in player logbook.
I.e. default length for one symbols it this function will taken equal to two spaces.
In fact some symbols have length more then two spaces, some - less.
Function use special array, was prepared in setup script by experimental data form text files x8910.xml.
Now supported only English, Russian, and German languages.
If length source string more then needed length - string will be truncated.
See examples:
If you browser support animated gif -
[ external image ] [ external image ]
Or if not:
output without 'fill.spaces'
[ external image ][ external image ]
output wtih 'fill.spaces'
[ external image ][ external image ]
3,4 'sum.to.string' and 'number.to.string'
Arg1 - integer
return - string
will do convert number 1234567890 to string like 1,234,567,890 or
will do convert sum 1234567890 to string like 1,234,567,890 Cr (add default name of games currency)
5,6 'fill.sum.to.string' and 'fill.number.to.string'
Arg1 - integer
Arg2 - max length
Arg3 - TRUE - fill left (align right) or FALSE - fill right (align left)
return - string
will do convert number 1234567890 to string like 1,234,567,890 or
will do convert sum 1234567890 to string like 1,234,567,890 Cr (add default name of games currency)
Then fill converted string as it can be done via 'fill.spaces'
7 'sprintf'
Arg1 -
if string
- then format string
else if number
- page id for format string
Arg2
if Arg1 = page id
- then text id for format string
else if
- array - then array of params
else
- params
Arg3..Arg5 - params or array of params like Arg2
if param is string and has form (page;id) then it will be replaced with string from text file
Function works like sprintf function from ScE, but use unlimited count of params and extended syntax:
%[align][width]specifier
align:
- - left
= - center
+ - right (default)
width: needed width of string in pseudo symbols
specifier:
n - number
c - currency
s - string
8 'length'
Arg1 - source string, or string from text file by page id Arg1 and text id Arg2
Arg2 or Arg3- - type of measurement units.
if [TRUE] - then result will be returned in spaces
otherwise - in pseudosymbols.
This function will return displayed length of source string.
_____________
Uninstallation:
Uninstall via Cycrow Script Manager (or Plugin Manager)
_____________
Languages:
Russian
English
Deutsch - thanks to Unitrader [KGB]
_____________
Info:
Uses
Text Files Used : 8910
Text Pages Used:8910
_____________
Script : Chem String Functions Library
Author : Chem
E-mail : chemodun@gmail.com
Web : http://www[dot]elite-games[dot]ru/x3/
Version: 2.81
Desc. :Provide some functions for manipulate with string,
based on their displayed width
################################################################################
_____________
Download:
Spk version
Zip version
History :
2.81
-added new function 'length', it return displayed width of string. If second parameter are [TRUE] - then length will be returned in spaces, otherwise - in pseudosymbols
2.78
-fixed error in functions 'fill.spaces', if used possibility read string from file - it's work incorrectly (Big thanks to X-Freak Cartman [KBG])
-used new version of .spk
2.76
-fixed error with aligning in functions 'fill.spaces', where aling = [FALSE] (Was - filled left, but must be - filled right)
2.75
- fixed error in definition aligining in functions 'fill.spaces', 'fill.sum.to.string', 'fill.number.to.string'
- added new function 'sprintf'
- functions 'fill.spaces', 'sprintf', 'split.string.by.delim' can use as parameters string, and integer vaules( for reading strings from text files)
- all functions corretly work with 2 bytes symbols (like Russian)
- if string are longer then must be displayet - it's truncated
2.09 - first public release
_____________
Installation :
Install via Cycrow Script Manager (Plugin Manager)
_____________
Use:
Libraries has two script files:
setup.lib.chem.string.xml - this file prepare special array for filling string by space.
Script doesn't have any parameters.
lib.chem.strings.xml - main library script.
Script has 6 parameters:
mode (Work Mode) - for defining which function called from library
Arg1..Arg5 - for setting functions parameters
Now in version 2.81 library provide 8 functions:
1. split.string.by.delim
Arg1 - string-delimeter - string, or string from text file by page id Arg1 and text id Arg2
Arg2 - string-source - string, or string from text file by page id Arg2(or Arg3) and text id Arg3 (or $Arg4)
Arg3 - max count parts of source string (if null - max count = 99)
return - array of found parts of source string
It's function can split source string (first) by delimeter (second).
You can set maximum count of parts for splitting (Arg3), i.e. if source has more then one occurrence of delimiter , but you set Arg3 = 2 - function will return array with only 2 elements, first - source string before first occurrence of Arg1 in Arg2, and second - all source after this first occurrence.
2.'fill.spaces' - you can create string with correct displayed width in player logbook, i.e. after using this function on, for example, strings "this is long string" and "small string", they will be filled by spaces up to they width in pixels (not symbols) will be equal.
Arg1 - source string, or string from text file by page id Arg1 and text id Arg2
Arg2 or Arg3- max len (in spaces, i.e. count of sybols " ")
Arg3 or Arg4- fill
if bool
TRUE - fill left (align right)
FALSE - fill right (align left)
if string
'-' - align left
'=' - align center
'+' - align right
It's function will fill source string by spaces based not on count of symbols in string, but on their summary width on screen in player logbook.
I.e. default length for one symbols it this function will taken equal to two spaces.
In fact some symbols have length more then two spaces, some - less.
Function use special array, was prepared in setup script by experimental data form text files x8910.xml.
Now supported only English, Russian, and German languages.
If length source string more then needed length - string will be truncated.
See examples:
If you browser support animated gif -
[ external image ] [ external image ]
Or if not:
output without 'fill.spaces'
[ external image ][ external image ]
output wtih 'fill.spaces'
[ external image ][ external image ]
3,4 'sum.to.string' and 'number.to.string'
Arg1 - integer
return - string
will do convert number 1234567890 to string like 1,234,567,890 or
will do convert sum 1234567890 to string like 1,234,567,890 Cr (add default name of games currency)
5,6 'fill.sum.to.string' and 'fill.number.to.string'
Arg1 - integer
Arg2 - max length
Arg3 - TRUE - fill left (align right) or FALSE - fill right (align left)
return - string
will do convert number 1234567890 to string like 1,234,567,890 or
will do convert sum 1234567890 to string like 1,234,567,890 Cr (add default name of games currency)
Then fill converted string as it can be done via 'fill.spaces'
7 'sprintf'
Arg1 -
if string
- then format string
else if number
- page id for format string
Arg2
if Arg1 = page id
- then text id for format string
else if
- array - then array of params
else
- params
Arg3..Arg5 - params or array of params like Arg2
if param is string and has form (page;id) then it will be replaced with string from text file
Function works like sprintf function from ScE, but use unlimited count of params and extended syntax:
%[align][width]specifier
align:
- - left
= - center
+ - right (default)
width: needed width of string in pseudo symbols
specifier:
n - number
c - currency
s - string
8 'length'
Arg1 - source string, or string from text file by page id Arg1 and text id Arg2
Arg2 or Arg3- - type of measurement units.
if [TRUE] - then result will be returned in spaces
otherwise - in pseudosymbols.
This function will return displayed length of source string.
_____________
Uninstallation:
Uninstall via Cycrow Script Manager (or Plugin Manager)
_____________
Languages:
Russian
English
Deutsch - thanks to Unitrader [KGB]
_____________
Info:
Uses
Text Files Used : 8910
Text Pages Used:8910
_____________
Last edited by ChemODun on Sat, 18. Aug 07, 22:27, edited 14 times in total.
Multiply entropy by absolute zero
Ñâîáîäà ñðåäè çâåçä / Freedom in space
Ñâîáîäà ñðåäè çâåçä / Freedom in space
stillsphr wrote:Is Chem still around and interested in maintaining the lib?
If not, I was thinking it would be possible to get permission to continue to maintain this lib as a part in the Common Library that I proposed much earlier.
Sorry, host was down.
Now hosten on Xai Corp - great host
thanks Moggy!
Multiply entropy by absolute zero
Ñâîáîäà ñðåäè çâåçä / Freedom in space
Ñâîáîäà ñðåäè çâåçä / Freedom in space
When I finish writing readme - you can use new function:
All old are still exists, for backward compability.
All old are still exists, for backward compability.
new wrote: sprintf - like standart in ScE, but with new format:
%[align][width]specifier
align:
- - left
= - center
+ - right (default)
width:
needed width of string in pseudo symbols
specifier:
n - number
c - currency
s - string
compability with first release wrote: sum.to.string
number.to.string
fill.spaces
fill.sum.to.string
fill.number.to.string
updated wrote: split.string.by.delim - now work wtih two bytes symbols (like russian). Additionally it will have short name split
Multiply entropy by absolute zero
Ñâîáîäà ñðåäè çâåçä / Freedom in space
Ñâîáîäà ñðåäè çâåçä / Freedom in space
- X-Freak Cartman
- Posts: 4017
- Joined: Mon, 2. Oct 06, 15:08
New version - 2.75
- fixed error in definition aligining in functions 'fill.spaces', 'fill.sum.to.string', 'fill.number.to.string'
- added new function 'sprintf'
- functions 'fill.spaces', 'sprintf', 'split.string.by.delim' can use as parameters string, and integer vaules( for reading strings from text files)
- all functions corretly work with 2 bytes symbols (like Russian)
- fixed error in definition aligining in functions 'fill.spaces', 'fill.sum.to.string', 'fill.number.to.string'
- added new function 'sprintf'
- functions 'fill.spaces', 'sprintf', 'split.string.by.delim' can use as parameters string, and integer vaules( for reading strings from text files)
- all functions corretly work with 2 bytes symbols (like Russian)
Multiply entropy by absolute zero
Ñâîáîäà ñðåäè çâåçä / Freedom in space
Ñâîáîäà ñðåäè çâåçä / Freedom in space
- X-Freak Cartman
- Posts: 4017
- Joined: Mon, 2. Oct 06, 15:08
Hmm... either you changed the function of 'fill.spaces' to 'simply add spaces' or the sentence above is a bit wrong.ChemODun wrote:all functions corretly work with 2 bytes symbols (like Russian)
Seems as if your script simply adds spaces if I use the same arguments i used for version 2.09... Afaik, it should be compatible, shouldn't it?
I'll try to find an error in your code, but now, the new version is useless to me...
btw: Arguments
mode: 'fill.spaces'
Arg1: 'Testtext'
Arg2: 1, 2, 3, 5, 10, 20 and 30.
Arg3: 1, TRUE, -1
In version 2.09, the first five Arg3's had the same effect, now the number of spaces seems to simply be added.
Thanks, fixed for Arg3 = [FALSE] (must be fill right, i.e align left).
2.76
-fixed error with aligning in functions 'fill.spaces', where aling = [FALSE] (Was - filled left, but must be - filled right)
But I don't understand, what wrong?
I was check with
[ external image ]
[ external image ]
[ external image ]
Or I want don't truncate string, if it more long, then Arg3 ?
2.76
-fixed error with aligning in functions 'fill.spaces', where aling = [FALSE] (Was - filled left, but must be - filled right)
But I don't understand, what wrong?
I was check with
Code: Select all
001 load text: id=8910
002 $out = ' '
003 $arg1 = 'Testtext'
004 $arg2 = array alloc: size=0
005 append 1 to array $arg2
006 append 2 to array $arg2
007 append 3 to array $arg2
008 append 5 to array $arg2
009 append 10 to array $arg2
010 append 20 to array $arg2
011 append 30 to array $arg2
012 $arg3 = array alloc: size=0
013 append 1 to array $arg3
014 append [TRUE] to array $arg3
015 append -1 to array $arg3
016 append [FALSE] to array $arg3
017
018 $arg3.l = size of array $arg3
019 while $arg3.l
020 dec $arg3.l =
021 $arg3.c = $arg3[$arg3.l]
022 $arg2.l = size of array $arg2
023 while $arg2.l
024 dec $arg2.l =
025 $arg2.c = $arg2[$arg2.l]
026 @ $result = [THIS] -> call script 'lib.chem.strings' : Work Mode='fill.spaces' Arg1=$arg1 Arg2=$arg2.c Arg3=$arg3.c Arg4=null Arg5=null
027 $result = sprintf: fmt='|%s| arg2=%s, arg3=%s', $result, $arg2.c, $arg3.c, null, null
028 $out = sprintf: pageid=8910 textid=1098, $out, $result, null, null, null
029 end
030 end
031 write to player logbook $out
032 return null
[ external image ]
[ external image ]
Or I want don't truncate string, if it more long, then Arg3 ?
Multiply entropy by absolute zero
Ñâîáîäà ñðåäè çâåçä / Freedom in space
Ñâîáîäà ñðåäè çâåçä / Freedom in space
- X-Freak Cartman
- Posts: 4017
- Joined: Mon, 2. Oct 06, 15:08
- X-Freak Cartman
- Posts: 4017
- Joined: Mon, 2. Oct 06, 15:08
What about a new version 2.77?
I could offer a Download. 2.76 has a major problem I recognised while using it for GAIUS:
Whatever $Arg.String has been defined as in the read-text-subsection of the script, it always used Arg1 as source and Arg2 as length.
Well, there's an easy fix for that:
That's all. It works properly and is ready for Download.
btw: You're allowed to use my server as a mirror. Just send me a PN and/or e-mail if you're releasing a new version and I'll upload it.
Edit: Links removed
I could offer a Download. 2.76 has a major problem I recognised while using it for GAIUS:
Code: Select all
087 end
089 $source = $Arg1
090 $out.len = $Arg2
091 skip if not $debug
Well, there's an easy fix for that:
Code: Select all
087 end
088 $source = $Arg.String
089 skip if not $debug
btw: You're allowed to use my server as a mirror. Just send me a PN and/or e-mail if you're releasing a new version and I'll upload it.
Edit: Links removed
Last edited by X-Freak Cartman on Sat, 18. Aug 07, 12:27, edited 1 time in total.
- X-Freak Cartman
- Posts: 4017
- Joined: Mon, 2. Oct 06, 15:08
- X-Freak Cartman
- Posts: 4017
- Joined: Mon, 2. Oct 06, 15:08
While working at a statistics script, I recognised that there was a simple error: The text (ship name) was too long, so it took two lines - which looked pretty... strange.
So, to the point, now i need a function that tells me either how long a string is (in spaces) or how many lines it takes when using a specific format ([text cols='4'] for example.)
So who'd I have to ask for that? You of course.
btw: There are 21 spaces fitting in one line, if you use [text cols='
4']. I didn't test 1,2 and 3 and colspacing yet... but as there aren't more than 4 cols possible, it shouldn't be a huge problem.
It's awesome if you can include such a function (or maybe both of 'em?), as i really need it for GAIUS.
So, to the point, now i need a function that tells me either how long a string is (in spaces) or how many lines it takes when using a specific format ([text cols='4'] for example.)
So who'd I have to ask for that? You of course.
btw: There are 21 spaces fitting in one line, if you use [text cols='
4']. I didn't test 1,2 and 3 and colspacing yet... but as there aren't more than 4 cols possible, it shouldn't be a huge problem.
It's awesome if you can include such a function (or maybe both of 'em?), as i really need it for GAIUS.
Understand.
But, if you don't use in each column any "[select]" (i.e. only one [select][/select] per screen line) - you don't need to use [text cols="x"].
You can use format string like
with function "sprintf" from my library.
Max width of message screen are 100 symbols.
for when you use [text cols] - we can define width only via experiments.
But, if you don't use in each column any "[select]" (i.e. only one [select][/select] per screen line) - you don't need to use [text cols="x"].
You can use format string like
Code: Select all
<t id="20025">%-15s\033C%-40s\033X\033C%-40s\033X\n</t>
<t id="20026">%-15s\033W%-40s\033X\033A%-40s\033X\n</t>
<t id="20027">%-25s\033W%-50s\033X\n</t>
Max width of message screen are 100 symbols.
for when you use [text cols] - we can define width only via experiments.
Multiply entropy by absolute zero
Ñâîáîäà ñðåäè çâåçä / Freedom in space
Ñâîáîäà ñðåäè çâåçä / Freedom in space
- X-Freak Cartman
- Posts: 4017
- Joined: Mon, 2. Oct 06, 15:08
For me, it's enough if you can return the length of the string in spaces. It'll be no problem for me to use it for my script ^^
The space-length of strings isn't only a problem for texts with more than a single column, it's also a problem i had with some other strings. It doesn't matter if you use your way or the column-way, however, the text has to be splitted to be shown correctly. The only question is, how to decide, where it has to be split.
My idea was to split the text into its single words by using your lib:
"Xenon Barracuda Raider" becomes an array including "Xenon", "Barracuda" and "Raider". Now, i can try, if they fit into one column (no matter if it's made by using "real" columns or a text-trick).
For example:
"Xenon" fits into a column.
"Xenon Barracuda" also fits into a column
"Xenon Barracuda Raider" doesn't fit into a column as it's longer than the given 21 spaces. So, the text has to be split into the following pieces:
"Xenon Barracuda" and "Raider".
That's done by the engine itself. The only thing to know is, how many lines it takes. As the text has to be split once, it takes two lines. That's all ^^
Maybe, you can include a function which tells, how many lines the text Arg1 takes if the text can be Arg2 wide in maximum.
Just an idea ^^
The space-length of strings isn't only a problem for texts with more than a single column, it's also a problem i had with some other strings. It doesn't matter if you use your way or the column-way, however, the text has to be splitted to be shown correctly. The only question is, how to decide, where it has to be split.
My idea was to split the text into its single words by using your lib:
"Xenon Barracuda Raider" becomes an array including "Xenon", "Barracuda" and "Raider". Now, i can try, if they fit into one column (no matter if it's made by using "real" columns or a text-trick).
For example:
"Xenon" fits into a column.
"Xenon Barracuda" also fits into a column
"Xenon Barracuda Raider" doesn't fit into a column as it's longer than the given 21 spaces. So, the text has to be split into the following pieces:
"Xenon Barracuda" and "Raider".
That's done by the engine itself. The only thing to know is, how many lines it takes. As the text has to be split once, it takes two lines. That's all ^^
Maybe, you can include a function which tells, how many lines the text Arg1 takes if the text can be Arg2 wide in maximum.
Just an idea ^^
No.Cycrow wrote:there already is a string length command in the script editor
My libraru works with displayed length of symbols.
Becouse font in message window are not monospace, then all symbols has different length.
I.E.
word
"fighters"
and
"destroer"
have identical length in 8 symbols, but they have different legth on screen.
My library operate with displayed length of each symbol (and string).
I was use pseudo measurement unit - "one symbol".
witdh of "one symbol" equal 2 width of symbol " ", i.e. space.
Full width of message window in game are equal 100 pseudo symbols, i.e. 200 spaces.
fucntion "fill.spaces" and "sprintf" operates with this measurement units.
Unerstand - ok, I will tryX-Freak Cartman [KBG] wrote: For example:
"Xenon" fits into a column.
"Xenon Barracuda" also fits into a column
"Xenon Barracuda Raider" doesn't fit into a column as it's longer than the given 21 spaces. So, the text has to be split into the following pieces:
"Xenon Barracuda" and "Raider".
Last edited by ChemODun on Sat, 18. Aug 07, 21:01, edited 1 time in total.
Multiply entropy by absolute zero
Ñâîáîäà ñðåäè çâåçä / Freedom in space
Ñâîáîäà ñðåäè çâåçä / Freedom in space