• Models
  • Contests
  • Slicer
  • Login
  • Start Here
    thingiverse-iconprintables-iconcults3d-iconmakerworld-iconmyminifactory-icon

    3D GO

    3D ModelsContestsCollectionsSaved ModelsOn a mobile device?

3D GO

Privacy Policy
String Theory, a string library for OpenSCAD 3D Printer File Image 1
String Theory, a string library for OpenSCAD 3D Printer File Thumbnail 1

String Theory, a string library for OpenSCAD

16807user avatar16807user

November 2, 2014

thingiverse-icon
DescriptionCommentsTags

Description

This library is a spin off of Relativity, my other OpenSCAD library. I needed a string processing library for some more advanced features I wanted to implement, and since none were available to my liking I rolled my own.
The library includes the following functions:

  • before(string, end)
  • after(string, start)
  • between(string, start, end)
  • substring(string, start, length)
  • upper(string)
  • lower(string)
  • title(string)
  • is_empty(string)
  • is_null_or_empty(string)
  • is_null_or_whitespace(string)
  • equals(this, that, ignore_case=false)
  • starts_with(string, start, ignore_case=false)
  • ends_with(string, end, ignore_case=false)
  • reverse(string)
  • trim(string)
  • parse_int(string, base)
  • parse_float(string)
  • tokenize(string, index)
  • join(strings, delimiter)
  • split(string, seperator=" ", ignore_case = false)
  • index_of(string, goal, ignore_case=false, regex=false)
  • contains(string, substring, ignore_case=false, regex=false)
  • replace(string, replaced, replacement, ignore_case=false, regex=false)
  • grep(string, pattern)
  • peg(string, grammar)

All functions are compatible with the latest production release of OpenSCAD, 2015.03. No dev release needed. For those still using version 2014.03, you can still use the older version of the library by checking the project history on Github.

Code shares its repository with relativity.scad: https://github.com/davidson16807/relativity.scad/blob/master/strings.scad

11/5/2022 Here's all y'all's reminder to go out and vote soon. The development phase of strings.scad has completed successfully for sometime now. To make it official: this project will remain in maintenance mode for the foreseeable future. I am still gladly accepting pull requests for fixes and features, however users may have to expect long response times. If anyone would like to help out in maintaining the project, let me know here and I can make arrangements. In the meantime, I have taken several suggestions and pull requests from the past few years and have made a new release. Big thanks goes to Bradk3 for his suggested implementation of title case conversion, and TheHeadlessSourceMan for his suggested implementation for float parsing. Both are now implemented in the latest version as "title(string)" and "parse_float(string)".

2/2/2015 That right woodchuck chuckers, it's Groundhog's Day. A new function has been added, called peg(). This function offers support for parsing expression grammars. Parsing expression grammars allow you to create your own mini programming languages within OpenSCAD. The engine is currently too slow to describe complex languages using Backus-Naur form, but for now you can specify grammars using an intermediate format that uses nested lists. Look to _rx_peg in the string.scad source code for an example grammar - this is the grammar used within strings.scad to describe regular expressions. You can also find some nacent documentation available here

3/17/2015 Happy Patty's Day. Thanks to new functionality in 2015.03, all string processing functions return a list of strings, where appropriate; e.g. grep() now returns a list of strings matching the input regex.

11/27/2014 Thanksgiving update. Regex now supports negative character sets ("[^aeiou]"), character ranges ("[a-z]"), and curly bracket repetition (".{2,3}").

11/13/2014 Added regular expression engine. The engine supports all basic regex operators ("|", "*", "+", "?", "."), anchors ("^", "$"), character sets ( "[...]"), metacharacters ("d","s", "w"), parentheses, and operator precedence. Regex functionality is exposed where ever there is a "regex" parameter flag in a method's signature, and of course, through grep().

License:

GNU - GPL

Related Models

NUT JOB | Nut, Bolt, Washer and Threaded Rod Factory preview image

NUT JOB | Nut, Bolt, Washer and Threaded Rod Factory

mike_mattala profile image

mike_mattala

51,797

Filament Sample Box | Infill / Color Swatch | Fully Printable preview image

Filament Sample Box | Infill / Color Swatch | Fully Printable

Extrutim profile image

Extrutim

8,975

Lock Library Shackle Tag preview image

Lock Library Shackle Tag

adam.fourney profile image

adam.fourney

17

Parametric pulley - lots of tooth profiles preview image

Parametric pulley - lots of tooth profiles

droftarts profile image

droftarts

35,582

Minimal Linework Bookmarks preview image

Minimal Linework Bookmarks

Bamingo Design profile image

Bamingo Design

3,169

Book Rating Tags preview image

Book Rating Tags

Michael.C profile image

Michael.C

43

Low-Poly Pikachu preview image

Low-Poly Pikachu

flowalistik profile image

flowalistik

30,461

Filament Swatch Library preview image

Filament Swatch Library

LinearRelation profile image

LinearRelation

843