MODULE: StringPlus v3.2 - Updated 17 March 2009

Started by monkey0506, Sat 21/05/2005 02:57:10

Previous topic - Next topic

monkey0506

Ladies and gentlemen, allow me to present StringPlus, the successor of StrAdditions. Now with over 40 functions to increase your productivity, creativity, fertility, and your enjoyment of String functionality in AGS!

As a special treat, I've included no documentation! :=

If you have any questions feel free to ask. I'm working on the documentation now...in-between my job. ;)

Requires AGS 3.1.2+

Download v3.2
Mirror

Download v3.1 Thanks Neole!

RickJ

Monkey,

Conrats on doing your first module.  Several of us had an extnsive discussion on what conventions we should use so as to make script modules as useful as possible.  You can find that discussion here:

http://www.adventuregamestudio.co.uk/yabb/index.php?topic=18989.0

The following documents resulted from this discussion which you may also find useful.  They are not finalized yet as I have been hard at work updating the dem o game to be compliant with the new V2.7 lauguage.

http://www.gaia-spa.com/project/ags/doc/ModuleProgrammingGuidlines.txt
http://www.gaia-spa.com/project/ags/doc/ModuleScriptTemplate.txt
http://www.gaia-spa.com/project/ags/doc/ModuleHeaderTemplate.txt

Cheers

monkey0506

Thanks Rick.  I've made some corrections.  Thinks like the documentation will be put off till probably tomorrow...Then I'll re-release it.

Rui 'Trovatore' Pires

Well done, I'm upping it to my site.
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

monkey0506

#4
You may want to hold off on that for a second...It doesn't currently meet specifications, but I'll bring that up to date tomorrow.  Right now I'm working on another SM (DlgScroll) which is the reason why I created this one in the first place, so I don't have time ATM to mess with this one anymore.  I'll probably make the documentation and stuff tomorrow.  BTW, thanks to (I think) Radiant (I don't remember if it was Radiant that helped me with StrCutByWidth (provided the code) originally, but I have re-written it several times successfully without realizing it due to something else I discovered in regards to label text display...) for his help with the original code (since lost in translation) and the inspiration to do this, by showing me that such things are possible.

Edit:  Also, just for the record, most of these functions are fairly simple (and small) to code, but they can become tedious if you find yourself re-writing the same code 10 - 20 times within a single function...(a.k.a. a motive!)

Rui 'Trovatore' Pires

Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

monkey0506

#6
http://www27.brinkster.com/meleepta/AGS/StrAdd.zip

[Edit:  The above link is obsolete.]

This should be up to specifications now...I'll delete the other link and Mrs. Brisby, erm... :o ::) :o, Rui, feel free to "up" it to your site.

Edit:  Actually I don't think I allowed users to edit the module script, but that's okay.  It makes it more like part of the engine that way... ;D

Rui 'Trovatore' Pires

QuoteActually I don't think I allowed users to edit the module script, but that's okay.  It makes it more like part of the engine that way...

Ok, if you won't change that behaviour I'll up it first thing in the morning.
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

monkey0506

I've been working on version 1.0 for some time now, and it's getting close to release.  I've changed a few things around, but I'm not quite finished with it yet.  Just wondering what you all think of the new changes.

For one thing, I've removed the StrFindFirst*OfReverse functions.  They have been implemented into their respective StrFindFirst*Of functions.


The StrFindFirst*Of functions (StrFindFirstOf and StrFindFirstNotOf) have new parameter lists, as follows:

string text /* string to be searched */
string delimiters /* series of characters to look for */
optional int start=0 /* starting position of search */
optional int length=0 /* length of search sub-string */

start and length control what part of (and what direction) the string is searched (in).  If length is positive, it will search between start and start+length for any of the characters in string delimiters (not in the string for StrFindFirstNotOf), returning the index of the first found (-1 for none).  If length is 0, it searches between start and the end of the string.  And finally, if length is negative, it searches in reverse from start, for start+length characters.


I'm also revising the StrCut* (excluding CutByWidth) functions so that you can cut any sub-string out of an existing string.


And I'm planning a function (possibly named StrReverse) to reverse any string (i.e., "some text" would become "txet emos").


I should be finished with this within a few days, I just couldn't wait to ask you guys what you all think about the new (and/or revised) functions.

monkey0506

#9
Well there's been a few versions gone past here and I don't really have anyone who appears to have used it, but version 2.0 is now up.

http://www.sitesled.com/members/meleepta/StrAdditions.rar
(Link and version obsoleted)

You can't currently use any of the functions with start and length parameters to search a substring in a negative position from the starting index, but if someone wants it, I could implement that.

Changes:

* Ensured that all Str* functions are old-style string compliant, and updated their code to be more efficient.
* Added StrAdditions struct with static functions to work with new String type.

monkey0506

#10
Year-old bump for new version!

(oh crap...I need to put a link lol)

And then I've got to go. So let me know what you guys think.

[EDIT:]

Yay bugs! I first realized that String.AsFloat wasn't introduced until AGS 2.72, and there was no check for that, so I added a check for that. Then I actually tried testing one of the old-style string functions (with AGS 2.72) and I got an error when trying to pass a string-literal through a string parameter. So I've had to add checks to see if the version of AGS is 2.71 or higher, and if it is, use const strings where applicable. To prevent duplicate autocomplete entries, I simply told it to ignore the actual imports, then added commented imports afterwards. Also I decided since StringAsFloat would autocomplete regardless of what I tried to stop it......aside from actually stopping it completely.....(i.e., if using AGS 2.71 or prior the function would still autocomplete even if it didn't exist)...instead I've made it so that if using AGS 2.71 or prior versions StringAsFloat will simply return the String's AsInt property IntToFloat-ed.

New functions Str[ing]FindLast[Not]Of and when I can decide on a reasonable name a contains-like function to return the last instance of the needle in the haystack will also ensue.

So there will be a new version coming shortly. Which is unfortunate because I always do this...when releasing a new version, 5 more always follow. I probably just release everything too early. Oh well.

11 October 2006 - I've uploaded v3.1 with the aforementioned bug fixes. I decided that StringContainsNth would be better than StringContainsLast because it would allow the user to find any instance of the needle String. Which led me to change StringFindFirstNotOf and StringFindFirstOf to StringFindNthNotOf and StringFindNthOf respectively, so that you can find the nth character in the String [not] contained by the second.

monkey0506

Bump. New name. New functions. New lack of documentation. Of course that's just replacing the old lack of hosting. :P

Dualnames

Quote from: monkey_05_06 on Sun 15/03/2009 18:55:48
Bump. New name. New functions. New lack of documentation. Of course that's just replacing the old lack of hosting. :P

To ask the obvious what the hell is the module about? String functions?
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

monkey0506

#13
It's over 40 new functions for Strings.

Quote// static methods - no extender support yet
String StringFromChar(char c, optional int padTo, optional bool zeroPad)
String StringFromFloat(float f, optional int precision, optional int padTo, optional bool zeroPad)
String StringFromInt(int i, optional int padTo, optional bool zeroPad)
String StringMergeArray(String array[], String glue)

// extender methods
String[] String.SplitByWidth(int width, FontType font, optional String delimiters, optional bool caseSensitive)
String[] String.SplitByString(String otherString, bool caseSensitive)
String[] String.SplitByCharacterSet(String characterSet, optional bool caseSensitive)
int String.ContainsHowManyOf(String characterSet, optional bool caseSensitive)
bool String.ContainsAllOf(String characterSet, optional bool caseSensitive)
bool String.ContainsNOf(String characterSet, int n, optional bool caseSensitive)
bool String.ContainsOnly(String characterSet, optional bool caseSensitive)
bool String.ContainsNoneOf(String characterSet, optional bool caseSensitive)
int String.IndexOfCase(String needle, optional bool caseSensitive)
int String.IndexOfChar(char c, optional bool caseSensitive)
int String.IndexOfNth(String needle, int n, optional bool caseSensitive, optional Direction searchDirection, optional bool returnLast)
int String.FindNthNotOf(String characterSet, int n, optional bool caseSensitive, optional Direction searchDirection, optional bool returnLast)
int String.FindNthOf(String characterSet, int n, optional bool caseSensitive, optional Direction searchDirection, optional bool returnLast)
bool String.StartsWithAllOf(String characterSet, optional bool caseSensitive)
bool String.StartsWithNOf(String characterSet, int n, optional bool caseSensitive)
bool String.StartsWithNoneOf(String characterSet, optional bool caseSensitive)
bool String.EndsWithAllOf(String characterSet, optional bool caseSensitive)
bool String.EndsWithNOf(String characterSet, int n, optional bool caseSensitive)
bool String.EndsWithNoneOf(String characterSet, optional bool caseSensitive)
String String.ReplaceCount(String lookForText, String replaceWithText, optional int count, optional bool caseSensitive)
String String.ReplaceNth(String lookForText, int n, String replaceWithText, optional bool caseSensitive, optional Direction searchDirection, optional bool useLast)
String String.ReplaceSubstring(int index, int length, String replaceWithText)
String String.RemoveSubstring(int index, int length)
String String.RemoveCharAt(int index)
String String.RemoveCharactersInSet(String characterSet, optional bool caseSensitive)
String String.RemoveCharactersNotInSet(String characterSet, optional bool caseSensitive)
String String.StripDuplicateChars(optional bool caseSensitive)
String String.InsertStringAt(int index, String otherString)
String String.InsertCharAt(int index, char newChar)
String String.Reverse()
bool String.IsLowerCase()
bool String.IsCharLowerCase(int index, bool alphaOnly)
String String.SetCharLowerCase(int index)
bool String.IsMixedCase()
bool String.IsUpperCase()
bool String.IsCharUpperCase(int index, bool alphaOnly)
String String.SetCharUpperCase(int index)
String String.InvertCase()
String String.InvertCharCase(int index)
bool String.IsAlphaNumeric()
bool String.IsCharAlpha(int index)
bool String.IsCharNumeric(int index)

Note: The function list has been modified since this list was compiled. The list has now been updated with the full 3.2 function list.

If you have a question regarding a specific function I'll be happy to oblige, but I'm actually working on the documentation for all of it as we speak. ;)

Dualnames

String Reverse? Wow, I'm so downloading this, wonder how I missed that!!
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

monkey0506

Yes, that is a wonder. :D

Anyway, I've taken this out of BETA now that I got the rest of the references to StrAdditions removed from the script, included AGS version enforcement, and documentation of all module functions. No other significant changes.

SMF spam blocked by CleanTalk