extString

Returns a extString.


Description

Extensions to String


Attributes Summary

Instance Properties: Regex Body

pitchClassNameRegexBody
pitchNameRegexBody

Instance Methods

capitalizeFirst
delimit
delimitByWhiteSpace
delimitWords
ditto
formatttt Returns a string.
formatColumn
partition
indent Prepend each non-blank line with whitespace.
dedent Remove the length of whitespace found at the start of the first line from all lines.
removeLeadingWhiteSpace Removes any whitespace between a newline and the first alphanumeric character, including tabs.
removeTabs Strips amy whitespace that appear after newline and before alphanumeric characters.
removeWhiteSpace !!! rename: stripWhiteSpace
splitLines Identical to splitlines in python.
strip Similar to strip in python.
title Capitalise the first letter of each word in string. Same as title in python.
toDashCase
toLowerDashCase
toLowerCamelCase
toLowerSnakeCase
toUpperCamelCase
toUpperDashCase
toUpperSnakeCase


Instance Properties: Regex Body


pitchClassNameRegexBody

  1. Example

    x ="Bb4 A#2 C3 Dbb1 A+7 A#+2 G~1 Gb~-3";
    m = x.findRegexp("".pitchClassNameRegexBody).flop[1];
    [ "Bb", "b", "A#", "#", "C", "", "Dbb", "bb", "A+", "+", "A#+", "#+", "G~", "~", "Gb~", "b~" ]


pitchNameRegexBody

  1. Example

    x ="Bb4 A#2 C3 Dbb1 A+7 A#+2 G~1 Gb~-3";
    m = x.findRegexp("".pitchNameRegexBody).flop[1];
    [ "Bb4", "b", "4", "A#2", "#", "2", "C3", "", "3", "Dbb1", "bb", "1", "A+7", "+", "7", "A#+2", "#+", "2", "G~1", "~", "1", "Gb~-3", "b~", "-3" ]
  2. Example

    x ="Bb4 A#2 <C3 Dbb1 A+7> A#+2 G~1 Gb~-3";
    m = x.findRegexp("<.*>").flop[1];
    [ "<C3 Dbb1 A+7>" ]


Instance Methods


capitalizeFirst

  1. Example

    "scale degrees 4 and 5.".capitalizeFirst;
    Scale degrees 4 and 5.


delimit

  1. Example

    x = "asd\nasdsad\nasdd";
    x.delimitBy("\\n");
    [ "asd", "asdsad", "asdd" ]


delimitByWhiteSpace

  1. Example

    "C#4 Ab Bb4 D5".delimitByWhiteSpace;
    [ "C#4", "Ab", "Bb4", "D5" ]


delimitWords

  1. Example

    "scale degrees 4 and 5.".delimitWords;
    [ "scale", "degrees", "4", "and", "5" ]
    "scale degrees 4and5.".delimitWords;
    [ "scale", "degrees", "4", "and", "5" ]
    "scaleDegrees4and5.".delimitWords;
    [ "scale", "Degrees", "4", "and", "5" ]
    "ScaleDegrees4and 5.".delimitWords;
    [ "Scale", "Degrees", "4", "and", "5" ]
    "scale-degrees-4-and-5.".delimitWords;
    [ "scale", "degrees", "4", "and", "5" ]
    "SCALE_DEGREES_4_AND_5.".delimitWords;
    [ "SCALE", "DEGREES", "4", "AND", "5" ]
    "one < two".delimitWords;
    [ "one", "<", "two" ]
    "one! two!".delimitWords;
    [ "one", "!", "two", "!" ]


ditto

  1. Example

    "blah".ditto;
    blahblah
    "blah".ditto(3);
    blahblahblah


formatttt

Returns a string.

  1. Example

    x = Array.geom(20, 1000, 7/10);
    x.collect { |n| n.format(precision: 3, width: 8) }.join("\n");
    1000.000
     700.000
     489.000
     342.000
     240.100
     168.070
     117.649
      82.354
      57.648
      40.354
      28.248
      19.773
      13.841
       9.689
       6.782
       4.748
       3.323
       2.326
       1.628
       1.140


formatColumn

  1. Example

    "".formatRow([1,2,3], 6, precision: 2);
    0.00  0.00  0.00


partition


indent

Prepend each non-blank line with whitespace.

  1. Example

    a = "1\n2\n\n4\n5";
    a.indent.cs;
    "    1
        2
    
        4
        5"
    a.indent(8).cs;
    "        1
            2
    
            4
            5"


dedent

Remove the length of whitespace found at the start of the first line from all lines.

WARNING/FIXME: will kill non-whitespace from subsequent lines with less leading whitespace!

  1. Example

    a = "    some text\n        with differently indented\n    lines.";
    a.dedent.cs;
    "some text
        with differently indented
    lines."


removeLeadingWhiteSpace

Removes any whitespace between a newline and the first alphanumeric character, including tabs.

  1. Example

    a = "Gets forbidden note duration.\n\n    Returns duration or nil.";
    b = a.removeLeadingWhiteSpace;
    Gets forbidden note duration.
    
    Returns duration or nil.


removeTabs

Strips amy whitespace that appear after newline and before alphanumeric characters.

  1. Example

    a = "Gets forbidden note duration.\n\n\tReturns duration or nil.";
    a.removeTabs;
    Gets forbidden note duration.
    
    Returns duration or nil.


removeWhiteSpace

!!! rename: stripWhiteSpace

  1. Example

    "scale degrees 4 and 5.".removeWhiteSpace;
    scaledegrees4and5.


splitLines

Identical to splitlines in python.

  1. Example

    "\none\ntwo\nthree".splitLines;
    "one\ntwo\nthree".splitLines;
    [ "one", "two", "three" ]


strip

Similar to strip in python.

  1. Example

    "__one_two__three___".strip($_);
    "__one_two__three___".strip("_");
    "   one  two   three  ".strip;
    one  two   three


title

Capitalise the first letter of each word in string. Same as title in python.

  1. Example

    "one two three-and-four".title;
    One Two Three And Four


toDashCase

  1. Example

    "scaleDegrees4and5.".toDashCase;
    "SCALE_DEGREES_4_AND_5.".toDashCase;
    "SCALE DEGREES 4 AND 5.".toDashCase;
    SCALE-DEGREES-4-AND-5


toLowerDashCase

  1. Example

    "scaleDegrees4and5.".toLowerDashCase;
    "SCALE_DEGREES_4_AND_5.".toLowerDashCase;
    scale-degrees-4-and-5


toLowerCamelCase

  1. Example

    "scale-degrees-4-and-5.".toLowerCamelCase;
    "SCALE_DEGREES_4_AND_5.".toLowerCamelCase;
    scaleDegrees4And5


toLowerSnakeCase

  1. Example

    "scaleDegrees4and5.".toLowerSnakeCase;
    "SCALE_DEGREES_4_AND_5.".toLowerSnakeCase;
    scale_degrees_4_and_5


toUpperCamelCase

  1. Example

    "scale-degrees-4-and-5.".toUpperCamelCase;
    "SCALE_DEGREES_4_AND_5.".toUpperCamelCase;
    ScaleDegrees4And5


toUpperDashCase

  1. Example

    "scale-degrees-4-and-5.".toUpperDashCase;
    "SCALE_DEGREES_4_AND_5.".toUpperDashCase;
    Scale-Degrees-4-And-5


toUpperSnakeCase

  1. Example

    "scale-degrees-4-and-5.".toUpperSnakeCase;
    "SCALE_DEGREES_4_AND_5.".toUpperSnakeCase;
    Scale_Degrees_4_And_5