Hello all!
Here is the second part where I’m going to explain some more features provided with this new release of my Helpers library.
BUFFERED STRINGS
Some time ago I was working on a project and I had the need to process long strings, character by character and I’ve noted that the code became slower with bigger strings so I started to analyze the problem and I’ve found a solution to achieve an huge boost in processing performances so BufferedStrings was born.
The trick I used can speed up a lot string operations, in my tests I was able to process strings with single character concatenation at around 18 Kb/s, using my system I was able to reach 680 Kb/s. Wow! You can verify by yourself just running the provided example.
For more informations about the methods included have a look at the docs page here.
COLOR OBJECT
From time to time I’ve the need darken or brighten a color and I’ve always to write the same formula again and again to accomplish this task so I decided to create an object and some methods to deal with colors.
The included methods allow to perform the following operations:
- Create a new color object
- Brighten a color
- Darken a color
- Clone a color object to another one
- Create a color object from standard ARGB values
- Convert a color object to Hollywood notation (single value)
- Generate a random color including a random alpha value
More detailed informations in this wiki page.
STRING UTILITIES
Included in the Helpers library there are also some functions that may help you with string manipulation, I created them to deal with custom tags and to process text with non-Hollywood compliant tags (like HTML pages for example). Here is a brief description:
- HL.CutBetweenLimits(…)
You provide a source string, a starting limit, and ending limit and this function will return the source text without the specified limits and any text within them into a table easy for you to further processing. - HL.GetBetweenLimits(…)
Similar to the previous one but it doesn’t modify the source string, instead it provides 2 tables with all found strings detected between the given limits you have specified. - HL.CutStringLeft(…) and HL.CutStringRight(…)
Sometimes you may have the need to produce strings that does not exceed a given number of character, especially if you are coding for the console. This two functions returns a cutted string if longer than the specified max size and add three dots (…) to indicate that the string has been trunkated, to the left or to the right,< - HL.SizeString(…)
Similar to the previous one, but this time, if the string is shorter than the specified length, this function will add spaces to poduce a string of exactly that requested size. It is very useful if you are coding a console program and you need to generate reports.
INPUT UTILITIES
Here are two general purpose routines to chek for user input, one to monitor the joystick and one to monitor the keyboard:
- HL.Input.CheckJoystick(…)
This function can be used both in continuos polling loops or it can wait for a joystick action to be detected, you can also specify if the function should return when the detected action is released or if it have to return immediatly. All available joystick will be checked and the direction and/or the button pressed will be returned.
Very useful is situations where you have to wait the user action to continue, or something like “Move the joystick to the right to confirm, or to the left to abort”, etc… - HL.Input.CheckKeyboard(…)
Using this function you can check the keyboard for a specific character (or more characters) to be pressed. It works like the previous function: it can return immediatly or it can return when a key press is detected. You can specify if the function should return immediatly at the event detection or when the key has been released.
PARSING ARGUMENTS
Hollywood already provide a way to get the arguments specified with the command line when you run a program from the console, but I’ve built the following function to simplify the process:
- HL.ParseRunArgs()
The purpose of this function is to parse command line arguments and to return a table indexed with the arguments found.
All the values in the argument-value pair will be returned as strings, it’s up to you to convert values in the needed formats.
This command is really usefull to test argument passed with the command line simply testing the resulting table keys that this function returns.
MISCELLANEOUS
Finally, within the library, you will find a function to generate random unique strings (you may use the results to index a table for example), and a function to convert values in percentual: you give the value, the value-range and the value in percentual form is returned.
And that’s all!
For more informations and detailed descriptions have a look at the Wiki!
Happy coding!