An open API service indexing awesome lists of open source software.

https://github.com/aziascreations/pb-utils

A collection of small independent includes for your PureBasic programs that aim to provided some missing and important functionalities.
https://github.com/aziascreations/pb-utils

endianness purebasic utilities uuid

Last synced: 4 months ago
JSON representation

A collection of small independent includes for your PureBasic programs that aim to provided some missing and important functionalities.

Awesome Lists containing this project

README

          

# Purebasic Utils
This repository contains a small collection of utilities designed to help you with specific tasks in PureBasic.

# This readme is out of date, please read the source code for the doc in the comments.

This repo is mostly a collection of small procdeures that can help in projects.

# Purebasic Utils
A small collection of utilities designed to help you in [programming in PB ?].

**Disclaimer:**

Some procedures are based on other people's code.

For each of them, credit is given in the source code files and in the [Credits](#credits) section.

And a url linking to the original thread or post is also given.

Every source code should work with EnableExplicit.

**Available utilities:**

  ● [Logger](#logger)

  ● [Semantic Versioning](#semantic-versioning)

  ● [Strings](#strings)

      ⚬ [ExplodeStringToArray()](#user-content-strings.explodestringtoarray)

      ⚬ [IsNullOrEmpty()](#user-content-strings.isnullorempty)

      ⚬ [Format()](#user-content-strings.format)

  ● [Unit Testing](#unit-testing-basic)

  ● [UUID4](#uuid4-logger-version--lite-version)

## Utilities
### [Logger](Logger.pb)

Click to expand
!!! A large portion of the formatter will be reworked when the Strings.Format() procedure is finished. !!!

This utility lets you easily log things to the console, debug window, or to a log file.

#### ◆ **Log file configuration**
`ConfigureLoggerOutputPath(LogFilePath.s="", KeepPreviousIfError.b=#True)`

[*]An empty string will disable the log file and ...

#### ◆ **Logging levels configuration**
`ConfigureLogLevels(LogFileLoggingLevel.b=..., DebugWindowLoggingLevel.b=..., ConsoleLoggingLevel.b=...)`

These 3 procedures allow you to configure each level independently:

    `ConfigureFileLogLevel(LogFileLoggingLevel.b)`

    `ConfigureDebugWindowLogLevel(DebugWindowLoggingLevel.b)`

    `ConfigureConsoleLogLevel(ConsoleLoggingLevel.b)`

Available logging levels:

    `#LoggingLevel_Trace` - "Super-debug" level

    `#LoggingLevel_Debug` -

    `#LoggingLevel_Fatal` -

    `#LoggingLevel_Error` -

    `#LoggingLevel_Warn` -

    `#LoggingLevel_Info` -

    `#LoggingLevel_Off` -

    `#LoggingLevel_Any` - Everything except the Trave level.

    `#LoggingLevel_Keep` - Only used internally or with `ConfigureLogFormats(...)`.

#### ◆ **Logging formats configuration**

`ConfigureLogFormats(TimeFormat.s="", DebugWindowLoggingFormat.s="", LogFileLoggingFormat.s="", ConsoleLoggingFormat.s="")`

This procedure will

These 4 procedure allow you to configure each format independently:

    `ConfigureTimeLogFormat(TimeFormat.s)`

    `ConfigureDebugWindowLogFormat(DebugWindowLoggingFormat.s)`

    `ConfigureFileLogFormat(LogFileLoggingFormat.s)`

    `ConfigureConsoleLogFormat(ConsoleLoggingFormat.s)`

The following [?] can be used in the format String:

    ● `%time%` will be replaced by the formatted time (`TimeFormat.s`).

    ● `%msg%` will be replaced by the message (`Message.s`).

    ● `%mbtitle%` will be replaced by the MessageBox title (`MBTitle.s`).

    ● `%mbmsg%` will be replaced by the MessageBox message (`MBMessage.s`).

Default formats:

    ● File: `"%time% - %msg%"`

    ● Time: `"%yy-%mm-%dd %hh:%ii:%ss"`

    ● Debug: `"%msg%"`

    ● Console: `"%msg%"`

#### ◆ **Usage**



### [Semantic Versioning](SemanticVersioning.pb)

InitializeSemVer(CanShowMessages.b=#False, CanEndProgram.b=#True)

IsVersionValid(Version.s, DoValidityCheck=#True)

GetVersionNumber(Version.s, CanShowMessages.b=#False, CanEndProgram.b=#True, DoValidityCheck=#True)

GetVersionMajor(Version.s, CanShowMessages.b=#False, CanEndProgram.b=#True, DoValidityCheck=#True)

GetVersionMinor(Version.s, CanShowMessages.b=#False, CanEndProgram.b=#True, DoValidityCheck=#True)

GetVersionPatch(Version.s, CanShowMessages.b=#False, CanEndProgram.b=#True, DoValidityCheck=#True)

IsVersionCompatible(VersionA.s, VersionB.s)


### [Strings](Strings.pb)

ExplodeStringToArray(Array a$(1), s$, d$)

  How it works:

    Explodes a given String(s$) at every given delimiter(d$) and stores the String parts in a given pre-initialized Array(a$).

  Returns :

    The number of occurences/sections in the given String.


    Or the amount of entries in the array.

IsNullOrEmpty(a$)

  Parameters:

    a$ - A String that will be analysed.

  Returns :

    A nonzero value if a$ is equal to #Null$, of length 0 or if it is filled with spaces characters (0x20).



Format(text.s, *val1=0, ..., *val11=0)
TEMP: This function isn't finished!

  How it works:

    ???

  Parameters:

    text.s - ???

    *val1 - ???

    *val11 - ???

  Formatting:

    ???

  Returns:

    The formatted String




### [Unit Testing](UnitTest-Basic.pb) (Basic)
This basic unit testing [module ???] utility gives you access to the following procedures and values:

Procedures:

`Assert(Bool.b, TestName.s="")`

    If `Bool.b` is true, the value of `PassedTests.i` will be incremented, otherwise, `FailedTests.i` will be.

    A condition can be passed as `Bool.b` if it is "wrapped" in a `Bool()` procedure.

`AssertTrue(Bool.b=#True, TestName.s="")`

    Same as `Assert()`, with a default value for `Bool.b`.

`AssertFalse(Bool.b=#False, TestName.s="")`

    The opposite of `AssertTrue()`.

`Pass(TestName.s="")`

    Will simply increment `PassedTests.i` and print "Passed" in the debug window

`Fail(TestName.s="")`

    Will simply increment `FailedTests.i` and print "Failed" in the debug window

Global Variables:

`PassedUnitTests.i`: The number of passed tests

`FailedUnitTests.i`: The number of failed tests

Remarks:

The `TestName.s` parameter is optional and will simply influence the text displayed in the debug window.

    "Passed" if `TestName.s` is empty or "Passed -> TestName.s" otherwise.


### [UUID4](UUID4.pb) ([Logger version](UUID4-Logger.pb))
In both version, you can generate a UUID4 by using the following procedure:

``GenerateUUID4()``

    Returns a UUID4 String that matches the standard.

``IsUUID4Compliant(uuid4$)``

    Returns a non-zero value if the string matches the regex.

You also have access to a regex (`#REGEX_ID_UUID4`) that lets you check if a String matches the UUID4 standard.

# Enumerations Used
* Regex (Used for regex IDs)
* ErrorCode (Used with `End [Integer]`)

# Usefull Links
* [cli-args-pb](https://github.com/aziascreations/cli-args-pb): Launch parameters parser

# Credits
The original authors and posts are also mentionned and linked in the source files.

● Demivec

     ⚬ Strings - `ExplodeStringToArray(...)`
  ([Thread](http://www.purebasic.fr/english/viewtopic.php?f=13&t=41704))

● Mistrel

     ⚬ UUID4 - Original GUID generator
  ([Thread](http://www.purebasic.fr/english/viewtopic.php?t=38008))

# License
[WTFPL](LICENSE)