string¶
Functions
Capitalizes start of string. |
|
Delimits words in string. |
|
Changes string from Roman numeral to digits. |
|
Is true when string starts with a letter and either 1. |
|
Is true when string is Roman numeral. |
|
Is true when string and is shoutcase. |
|
Normalizes string. |
|
Pluralizes English string. |
|
Sorts strings containing Roman numerals. |
|
Strips roman numerals from right of string. |
|
Changes string to shout case. |
|
Changes |
|
Changes |
|
Changes string to upper camel case. |
- abjad.string.capitalize_start(string)[source]¶
Capitalizes start of string.
Capitalizes only
string[0]
; leaves noninitial characters unchanged:>>> abjad.string.capitalize_start("violin I") 'Violin I'
Built-in
str.capitalize()
forces noninitial characters to lowercase:>>> "violin I".capitalize() 'Violin i'
- Return type:
- abjad.string.delimit_words(string, separate_caps=False)[source]¶
Delimits words in string.
>>> abjad.string.delimit_words("scale degrees 4 and 5.") ['scale', 'degrees', '4', 'and', '5']
>>> abjad.string.delimit_words("scale degrees 4and5.") ['scale', 'degrees', '4', 'and', '5']
>>> abjad.string.delimit_words("scaleDegrees4and5.") ['scale', 'Degrees', '4', 'and', '5']
>>> abjad.string.delimit_words("ScaleDegrees4and 5.") ['Scale', 'Degrees', '4', 'and', '5']
>>> abjad.string.delimit_words("scale-degrees-4-and-5.") ['scale', 'degrees', '4', 'and', '5']
>>> abjad.string.delimit_words("SCALE_DEGREES_4_AND_5.") ['SCALE', 'DEGREES', '4', 'AND', '5']
>>> abjad.string.delimit_words("one < two") ['one', '<', 'two']
>>> abjad.string.delimit_words("one! two!") ['one', '!', 'two', '!']
Separates capital letters when keyword is true:
>>> abjad.string.delimit_words("MRM") ['MRM']
>>> abjad.string.delimit_words("MRM", separate_caps=True) ['M', 'R', 'M']
>>> abjad.string.delimit_words("MRhM") ['MRh', 'M']
>>> abjad.string.delimit_words("MRhM", separate_caps=True) ['M', 'Rh', 'M']
- abjad.string.from_roman(string)[source]¶
Changes string from Roman numeral to digits.
>>> abjad.string.from_roman("IX") 9
>>> abjad.string.from_roman("ix") 9
Raises Roman numeral error when string is not Roman numeral:
>>> abjad.string.from_roman("Allegro") Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Users/trevor/abjad/abjad/string.py", line 143, in from_roman number = roman.fromRoman(string) ^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/trevor/.venv/abjad/lib/python3.11/site-packages/roman.py", line 111, in fromRoman raise InvalidRomanNumeralError('Invalid Roman numeral: %s' % s) roman.InvalidRomanNumeralError: Invalid Roman numeral: Allegro
- Return type:
- abjad.string.is_lilypond_identifier(string)[source]¶
Is true when string starts with a letter and either 1. contains only letters and underscores thereafter, or 2. contains only letters, numbers and dots thereafter.
>>> abjad.string.is_lilypond_identifier("ViolinOne") True
>>> abjad.string.is_lilypond_identifier("Violin_One") True
>>> abjad.string.is_lilypond_identifier("Violin One") False
>>> abjad.string.is_lilypond_identifier("ViolinI") True
>>> abjad.string.is_lilypond_identifier("Violin_I") True
>>> abjad.string.is_lilypond_identifier("Violin I") False
>>> abjad.string.is_lilypond_identifier("Violin1") False
>>> abjad.string.is_lilypond_identifier("Violin_1") False
>>> abjad.string.is_lilypond_identifier("Violin 1") False
>>> abjad.string.is_lilypond_identifier("Violin.1") True
>>> abjad.string.is_lilypond_identifier("Violin.1.1") False
>>> abjad.string.is_lilypond_identifier("Violin.1_1") False
>>> abjad.string.is_lilypond_identifier("Violin_1.1") False
>>> abjad.string.is_lilypond_identifier("Violin.1.MusicVoice.1") True
>>> abjad.string.is_lilypond_identifier("Violin.1.1.MusicVoice") False
>>> abjad.string.is_lilypond_identifier("Violin.1_Music_Voice") False
>>> abjad.string.is_lilypond_identifier("Violin.Music_Voice_1") False
>>> abjad.string.is_lilypond_identifier("Violin.1_Music_Voice") False
- Return type:
- abjad.string.is_roman(string)[source]¶
Is true when string is Roman numeral.
>>> abjad.string.is_roman("I") True
>>> abjad.string.is_roman("II") True
>>> abjad.string.is_roman("X") True
>>> abjad.string.is_roman("XI") True
>>> abjad.string.is_roman("C") True
>>> abjad.string.is_roman("CI") True
>>> abjad.string.is_roman("i") True
>>> abjad.string.is_roman("F") False
- Return type:
- abjad.string.is_shout_case(string)[source]¶
Is true when string and is shoutcase.
>>> abjad.string.is_shout_case("FOO_BAR") True
>>> abjad.string.is_shout_case("FooBar") False
- Return type:
- abjad.string.normalize(argument, indent=None)[source]¶
Normalizes string.
>>> string = r""" ... foo ... bar ... """ >>> print(string) foo bar
>>> print(abjad.string.normalize(string)) foo bar
>>> print(abjad.string.normalize(string, indent=4)) foo bar
>>> print(abjad.string.normalize(string, indent="* ")) * foo * bar
- Return type:
- abjad.string.pluralize(string, count=None)[source]¶
Pluralizes English string.
Changes terminal
-y
to-ies
:>>> abjad.string.pluralize("catenary") 'catenaries'
Adds
-es
to terminal-s
,-sh
,-x
and-z
:>>> abjad.string.pluralize("brush") 'brushes'
Adds
-s
to all other strings:>>> abjad.string.pluralize("shape") 'shapes'
Does not pluralize when
count
is 1:>>> abjad.string.pluralize("shape", count=1) 'shape'
- Return type:
- abjad.string.sort_roman(strings)[source]¶
Sorts strings containing Roman numerals.
>>> strings = ["TromboneII", "TromboneIII", "TromboneI"] >>> abjad.string.sort_roman(strings) ['TromboneI', 'TromboneII', 'TromboneIII']
>>> strings = ["ViolinXI", "ViolinX", "ViolinIX"] >>> abjad.string.sort_roman(strings) ['ViolinIX', 'ViolinX', 'ViolinXI']
- abjad.string.strip_roman(string)[source]¶
Strips roman numerals from right of string.
>>> abjad.string.strip_roman("Trombone") 'Trombone'
>>> abjad.string.strip_roman("TromboneI") 'Trombone'
>>> abjad.string.strip_roman("TromboneII") 'Trombone'
>>> abjad.string.strip_roman("TromboneIII") 'Trombone'
>>> abjad.string.strip_roman("TromboneIV") 'Trombone'
- Return type:
- abjad.string.to_shout_case(string)[source]¶
Changes string to shout case.
>>> abjad.string.to_shout_case("scale degrees 4 and 5") 'SCALE_DEGREES_4_AND_5'
>>> abjad.string.to_shout_case("scale_degrees_4_and_5") 'SCALE_DEGREES_4_AND_5'
>>> abjad.string.to_shout_case("scale-degrees-4-and-5") 'SCALE_DEGREES_4_AND_5'
>>> abjad.string.to_shout_case("ScaleDegrees4And5") 'SCALE_DEGREES_4_AND_5'
- Return type:
- abjad.string.to_tridirectional_lilypond_symbol(argument)[source]¶
Changes
argument
to tridirectional LilyPond symbol.>>> abjad.string.to_tridirectional_lilypond_symbol(abjad.UP) '^'
>>> abjad.string.to_tridirectional_lilypond_symbol(abjad.DOWN) '_'
>>> abjad.string.to_tridirectional_lilypond_symbol(1) '^'
>>> abjad.string.to_tridirectional_lilypond_symbol(0) '-'
>>> abjad.string.to_tridirectional_lilypond_symbol(-1) '_'
>>> abjad.string.to_tridirectional_lilypond_symbol("^") '^'
>>> abjad.string.to_tridirectional_lilypond_symbol("-") '-'
>>> abjad.string.to_tridirectional_lilypond_symbol("_") '_'
Returns none when
argument
is none:>>> abjad.string.to_tridirectional_lilypond_symbol(None) is None True
- abjad.string.to_tridirectional_ordinal_constant(argument)[source]¶
Changes
argument
to tridirectional ordinal constant.>>> abjad.string.to_tridirectional_ordinal_constant("^") <Vertical.UP: 1>
>>> abjad.string.to_tridirectional_ordinal_constant("_") <Vertical.DOWN: -1>
>>> abjad.string.to_tridirectional_ordinal_constant(1) <Vertical.UP: 1>
>>> abjad.string.to_tridirectional_ordinal_constant(-1) <Vertical.DOWN: -1>
>>> abjad.string.to_tridirectional_ordinal_constant(abjad.UP) <Vertical.UP: 1>
>>> abjad.string.to_tridirectional_ordinal_constant(abjad.DOWN) <Vertical.DOWN: -1>
>>> abjad.string.to_tridirectional_ordinal_constant(abjad.CENTER) <Vertical.CENTER: 0>
>>> abjad.string.to_tridirectional_ordinal_constant(None) is None True
- abjad.string.to_upper_camel_case(string)[source]¶
Changes string to upper camel case.
>>> abjad.string.to_upper_camel_case("scale degrees 4 and 5") 'ScaleDegrees4And5'
>>> abjad.string.to_upper_camel_case("scale_degrees_4_and_5") 'ScaleDegrees4And5'
>>> abjad.string.to_upper_camel_case("scale-degrees-4-and-5") 'ScaleDegrees4And5'
>>> abjad.string.to_upper_camel_case("ScaleDegrees4And5") 'ScaleDegrees4And5'
- Return type: