String

digraph InheritanceGraph { graph [bgcolor=transparent, color=lightsteelblue2, fontname=Arial, fontsize=10, outputorder=edgesfirst, overlap=prism, penwidth=2, rankdir=LR, splines=spline, style="dashed, rounded", truecolor=true]; node [colorscheme=pastel19, fontname=Arial, fontsize=10, height=0, penwidth=2, shape=box, style="filled, rounded", width=0]; edge [color=lightslategrey, penwidth=1]; subgraph "cluster_abjad.utilities" { graph [label="abjad.utilities"]; node [color=1]; "abjad.utilities.String.String" [URL="../api/abjad/utilities/String.html#abjad.utilities.String.String", color=black, fontcolor=white, label=String, target=_top]; } subgraph cluster_builtins { graph [label=builtins]; node [color=2]; "builtins.object" [URL="https://docs.python.org/3.6/library/functions.html#object", label=object, target=_top]; "builtins.str" [URL="https://docs.python.org/3.6/library/stdtypes.html#str", label=str, target=_top]; "builtins.object" -> "builtins.str"; } "builtins.str" -> "abjad.utilities.String.String"; }

class abjad.utilities.String.String

String.


Attributes Summary

base_26 Gets base-26 representation of nonnegative integer n.
capitalize_start Capitalizes start of string.
delimit_words Delimits words in string.
from_roman Changes string from Roman numeral to digits.
hyphen_delimited_lowercase_file_name_regex
hyphen_delimited_lowercase_file_name_regex_body
hyphen_delimited_lowercase_regex
hyphen_delimited_lowercase_regex_body
is_build_directory_name Is true when string is build directory name.
is_classfile_name Is true when string is classfile name.
is_dash_case Is true when string is hyphen-delimited lowercase.
is_dash_case_file_name Is true when string is hyphen-delimited lowercase file name with extension.
is_introduction_segment_name Is true when string is introductory segment name.
is_lilypond_identifier Is true when string starts with a letter and contains only letters and underscores thereafter.
is_lower_camel_case Is true when string and is lower camel case.
is_lowercase_file_name Is true when string is lowercase file name.
is_module_file_name Is true when string is module file name.
is_package_name Is true when string is package name.
is_public_python_file_name Is true when string is public Python file name.
is_rehearsal_mark Is true when string is one- or two-character rehearsal mark.
is_roman Is true when string is Roman numeral.
is_segment_name Is true when string is segment name or package name.
is_shout_case Is true when string and is shoutcase.
is_snake_case Is true when string is underscore-delimited lowercase.
is_snake_case_file_name Is true when string is underscore-delimited lowercase file name.
is_snake_case_file_name_with_extension Is true when string is underscore-delimited lowercase file name with extension.
is_snake_case_package_name Is true when string is underscore-delimited lowercase package name.
is_space_delimited_lowercase Is true when string is space-delimited lowercase.
is_string Is true when argument is a string.
is_stylesheet_name Is true when string is stylesheet name.
is_tools_file_name Is true when string is tools file name.
is_upper_camel_case Is true when string upper camel case.
lowercamelcase_regex
match_strings Matches pattern against strings.
match_word_starts Matches word starts.
normalize Normalizes string.
pluralize Pluralizes English string.
remove_zfill Removes zfill from numbers in string.
segment_letter Gets segment letter.
segment_rank Gets segment index.
sort_roman Sorts strings containing Roman numerals.
sort_segment_names Sorts segment name strings.
space_delimited_lowercase_regex
strip_diacritics Strips diacritics from string.
strip_roman Strips roman numerals from right of string.
to_accent_free_snake_case Changes string to accent-free snake case.
to_bidirectional_direction_string Changes argument to bidirectional direction string.
to_bidirectional_lilypond_symbol Changes argument to bidirectional LilyPond symbol.
to_dash_case Changes string to dash case.
to_indicator_stem Changes indicator to stem.
to_lower_camel_case Changes string to lower camel case.
to_segment_lilypond_identifier Changes string to segment LilyPond identifier.
to_shout_case Changes string to shout case.
to_snake_case Changes string to snake case.
to_space_delimited_lowercase Changes string to space-delimited lowercase.
to_tridirectional_direction_string Changes argument to tridirectional direction string.
to_tridirectional_lilypond_symbol Changes argument to tridirectional LilyPond symbol.
to_tridirectional_ordinal_constant Changes argument to tridirectional ordinal constant.
to_upper_camel_case Changes string to upper camel case.
underscore_delimited_lowercase_file_name_regex
underscore_delimited_lowercase_file_name_regex_body
underscore_delimited_lowercase_file_name_with_extension_regex
underscore_delimited_lowercase_file_name_with_extension_regex_body
underscore_delimited_lowercase_package_regex
underscore_delimited_lowercase_package_regex_body
underscore_delimited_lowercase_regex
underscore_delimited_lowercase_regex_body
uppercamelcase_regex

Special methods

(str).__add__()

Return self+value.

(str).__contains__()

Return key in self.

(str).__eq__()

Return self==value.

(str).__format__(format_spec) → str

Return a formatted version of S as described by format_spec.

(str).__ge__()

Return self>=value.

(str).__getitem__()

Return self[key].

(str).__gt__()

Return self>value.

(str).__hash__()

Return hash(self).

(str).__iter__()

Implement iter(self).

(str).__le__()

Return self<=value.

(str).__len__()

Return len(self).

(str).__lt__()

Return self<value.

(str).__mod__()

Return self%value.

(str).__mul__()

Return self*value.n

(str).__ne__()

Return self!=value.

(str).__new__()

Create and return a new object. See help(type) for accurate signature.

(str).__repr__()

Return repr(self).

(str).__rmod__()

Return value%self.

(str).__rmul__()

Return self*value.

(str).__str__()

Return str(self).


Methods

(str).capitalize() → str

Return a capitalized version of S, i.e. make the first character have upper case and the rest lower case.

capitalize_start()

Capitalizes start of string.

>>> abjad.String('violin I').capitalize_start()
'Violin I'

Capitalizes only string[0]; leaves noninitial characters unchanged.

Built-in string.capitalize() forces noninitial characters to lowercase:

>>> 'violin I'.capitalize()
'Violin i'
Return type:String
(str).casefold() → str

Return a version of S suitable for caseless comparisons.

(str).center(width[, fillchar]) → str

Return S centered in a string of length width. Padding is done using the specified fill character (default is a space)

(str).count(sub[, start[, end]]) → int

Return the number of non-overlapping occurrences of substring sub in string S[start:end]. Optional arguments start and end are interpreted as in slice notation.

delimit_words(separate_caps=False)

Delimits words in string.

>>> string = abjad.String('scale degrees 4 and 5.')
>>> string.delimit_words()
['scale', 'degrees', '4', 'and', '5']
>>> string = abjad.String('scale degrees 4and5.')
>>> string.delimit_words()
['scale', 'degrees', '4', 'and', '5']
>>> string = abjad.String('scaleDegrees4and5.')
>>> string.delimit_words()
['scale', 'Degrees', '4', 'and', '5']
>>> string = abjad.String('ScaleDegrees4and 5.')
>>> string.delimit_words()
['Scale', 'Degrees', '4', 'and', '5']
>>> string = abjad.String('scale-degrees-4-and-5.')
>>> string.delimit_words()
['scale', 'degrees', '4', 'and', '5']
>>> string = abjad.String('SCALE_DEGREES_4_AND_5.')
>>> string.delimit_words()
['SCALE', 'DEGREES', '4', 'AND', '5']
>>> string = abjad.String('one < two')
>>> string.delimit_words()
['one', '<', 'two']
>>> string = abjad.String('one! two!')
>>> string.delimit_words()
['one', '!', 'two', '!']

Separates capital letters when keyword is true:

>>> string = abjad.String('MRM')
>>> string.delimit_words()
['MRM']
>>> string.delimit_words(separate_caps=True)
['M', 'R', 'M']
>>> string = abjad.String('MRhM')
>>> string.delimit_words()
['MRh', 'M']
>>> string.delimit_words(separate_caps=True)
['M', 'Rh', 'M']
Return type:List[String]
(str).encode(encoding='utf-8', errors='strict') → bytes

Encode S using the codec registered for encoding. Default encoding is ‘utf-8’. errors may be given to set a different error handling scheme. Default is ‘strict’ meaning that encoding errors raise a UnicodeEncodeError. Other possible values are ‘ignore’, ‘replace’ and ‘xmlcharrefreplace’ as well as any other name registered with codecs.register_error that can handle UnicodeEncodeErrors.

(str).endswith(suffix[, start[, end]]) → bool

Return True if S ends with the specified suffix, False otherwise. With optional start, test S beginning at that position. With optional end, stop comparing S at that position. suffix can also be a tuple of strings to try.

(str).expandtabs(tabsize=8) → str

Return a copy of S where all tab characters are expanded using spaces. If tabsize is not given, a tab size of 8 characters is assumed.

(str).find(sub[, start[, end]]) → int

Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end]. Optional arguments start and end are interpreted as in slice notation.

Return -1 on failure.

(str).format(*args, **kwargs) → str

Return a formatted version of S, using substitutions from args and kwargs. The substitutions are identified by braces (‘{‘ and ‘}’).

(str).format_map(mapping) → str

Return a formatted version of S, using substitutions from mapping. The substitutions are identified by braces (‘{‘ and ‘}’).

from_roman()

Changes string from Roman numeral to digits.

>>> abjad.String('IX').from_roman()
9
>>> abjad.String('ix').from_roman()
9

Raises Roman numeral error when string is not Roman numeral:

>>> abjad.String('Allegro').from_roman()
Traceback (most recent call last):
    ...
roman.InvalidRomanNumeralError: Invalid Roman numeral: Allegro
Return type:int
(str).index(sub[, start[, end]]) → int

Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end]. Optional arguments start and end are interpreted as in slice notation.

Raises ValueError when the substring is not found.

is_build_directory_name()

Is true when string is build directory name.

>>> abjad.String('letter-score').is_build_directory_name()
True
>>> abjad.String('letter_score').is_build_directory_name()
True
>>> abjad.String('Letter_score').is_build_directory_name()
False
>>> abjad.String('-letter-score').is_build_directory_name()
False
>>> abjad.String('_letter-score').is_build_directory_name()
False
>>> abjad.String('letter score').is_build_directory_name()
False
Return type:bool
is_classfile_name()

Is true when string is classfile name.

>>> abjad.String('BeamSpecifier.py').is_classfile_name()
True
>>> abjad.String('BeamSpecifier').is_classfile_name()
False
>>> abjad.String('beamSpecifier.py').is_classfile_name()
False
>>> abjad.String('Beam_Specifier.py').is_classfile_name()
False
Return type:bool
is_dash_case()

Is true when string is hyphen-delimited lowercase.

>>> abjad.String('foo-bar').is_dash_case()
True
>>> abjad.String('foo bar').is_dash_case()
False
Return type:bool
is_dash_case_file_name()

Is true when string is hyphen-delimited lowercase file name with extension.

>>> abjad.String('foo-bar').is_dash_case_file_name()
True
>>> abjad.String('foo.bar.blah').is_dash_case_file_name()
False
Return type:bool
is_introduction_segment_name()

Is true when string is introductory segment name.

>>> abjad.String('_').is_introduction_segment_name()
True
>>> abjad.String('_1').is_introduction_segment_name()
True
>>> abjad.String('_2').is_introduction_segment_name()
True
>>> abjad.String('_99').is_introduction_segment_name()
True
>>> abjad.String('__').is_introduction_segment_name()
False
>>> abjad.String('__1').is_introduction_segment_name()
False
>>> abjad.String('A').is_introduction_segment_name()
False
>>> abjad.String('1').is_introduction_segment_name()
False
Return type:bool
is_lilypond_identifier()

Is true when string starts with a letter and contains only letters and underscores thereafter.

>>> abjad.String('ViolinOne').is_lilypond_identifier()
True
>>> abjad.String('Violin_One').is_lilypond_identifier()
True
>>> abjad.String('Violin One').is_lilypond_identifier()
False
>>> abjad.String('ViolinI').is_lilypond_identifier()
True
>>> abjad.String('Violin_I').is_lilypond_identifier()
True
>>> abjad.String('Violin I').is_lilypond_identifier()
False
>>> abjad.String('Violin1').is_lilypond_identifier()
False
>>> abjad.String('Violin_1').is_lilypond_identifier()
False
>>> abjad.String('Violin 1').is_lilypond_identifier()
False
Return type:bool
is_lower_camel_case()

Is true when string and is lower camel case.

>>> abjad.String('fooBar').is_lower_camel_case()
True
>>> abjad.String('FooBar').is_lower_camel_case()
False
Return type:bool
is_lowercase_file_name()

Is true when string is lowercase file name.

Is true when string is dash case:

>>> abjad.String('back-cover').is_lowercase_file_name()
True
>>> abjad.String('back-cover.tex').is_lowercase_file_name()
True

Is true when string is underscore-delimited:

>>> abjad.String('compile_source').is_lowercase_file_name()
True
>>> abjad.String('compile_source.py').is_lowercase_file_name()
True
>>> abjad.String('back cover').is_lowercase_file_name()
False
>>> abjad.String('Back-Cover').is_lowercase_file_name()
False
Return type:bool
is_module_file_name()

Is true when string is module file name.

>>> abjad.String('compile_source.py').is_module_file_name()
True
>>> abjad.String('compile_source').is_module_file_name()
False
>>> abjad.String('compile-source').is_module_file_name()
False
>>> abjad.String('compile-source.py').is_module_file_name()
False
>>> abjad.String('Compile_Source.py').is_module_file_name()
False
Return type:bool
is_package_name()

Is true when string is package name.

>>> abjad.String('pitches').is_package_name()
True
>>> abjad.String('pitch_classes').is_package_name()
True
>>> abjad.String('Pitches').is_package_name()
False
>>> abjad.String('pitch-classes').is_package_name()
False
Return type:bool
is_public_python_file_name()

Is true when string is public Python file name.

>>> abjad.String('pitches.py').is_public_python_file_name()
True
>>> abjad.String('pitch_classes.py').is_public_python_file_name()
True
>>> abjad.String('Pitches.py').is_public_python_file_name()
True
>>> abjad.String('PitchClasses.py').is_public_python_file_name()
True
>>> abjad.String('.pitches.py').is_public_python_file_name()
False
>>> abjad.String('_pitches.py').is_public_python_file_name()
False
>>> abjad.String('pitch-classes.py').is_public_python_file_name()
False
Return type:bool
is_rehearsal_mark(forbid_i=False)

Is true when string is one- or two-character rehearsal mark.

>>> abjad.String('A').is_rehearsal_mark()
True
>>> abjad.String('B').is_rehearsal_mark()
True
>>> abjad.String('Z').is_rehearsal_mark()
True
>>> abjad.String('AA').is_rehearsal_mark()
True
>>> abjad.String('AB').is_rehearsal_mark()
True
>>> abjad.String('AZ').is_rehearsal_mark()
True
>>> abjad.String('ZZ').is_rehearsal_mark()
True
>>> abjad.String('A1').is_rehearsal_mark()
False
>>> abjad.String('AAA').is_rehearsal_mark()
False
>>> abjad.String('I').is_rehearsal_mark()
True
>>> abjad.String('J').is_rehearsal_mark()
True
>>> abjad.String('I').is_rehearsal_mark(forbid_i=True)
False
>>> abjad.String('J').is_rehearsal_mark(forbid_i=True)
True
Return type:bool
is_roman()

Is true when string is Roman numeral.

>>> abjad.String('I').is_roman()
True
>>> abjad.String('II').is_roman()
True
>>> abjad.String('X').is_roman()
True
>>> abjad.String('XI').is_roman()
True
>>> abjad.String('C').is_roman()
True
>>> abjad.String('CI').is_roman()
True
>>> abjad.String('i').is_roman()
True
>>> abjad.String('F').is_roman()
False
Return type:bool
is_segment_name()

Is true when string is segment name or package name.

>>> abjad.String('_').is_segment_name()
True
>>> abjad.String('_1').is_segment_name()
True
>>> abjad.String('_99').is_segment_name()
True
>>> abjad.String('A').is_segment_name()
True
>>> abjad.String('A1').is_segment_name()
True
>>> abjad.String('A99').is_segment_name()
True
>>> abjad.String('AB').is_segment_name()
True
>>> abjad.String('AB1').is_segment_name()
True
>>> abjad.String('AB99').is_segment_name()
True
>>> abjad.String('segment_01').is_segment_name()
True
>>> abjad.String('__1').is_segment_name()
False
>>> abjad.String('A_1').is_segment_name()
False
>>> abjad.String('AB_1').is_segment_name()
False
Return type:bool
is_shout_case()

Is true when string and is shoutcase.

>>> abjad.String('FOO_BAR').is_shout_case()
True
>>> abjad.String('FooBar').is_shout_case()
False
Return type:bool
is_snake_case()

Is true when string is underscore-delimited lowercase.

>>> abjad.String('foo_bar').is_snake_case()
True
>>> abjad.String('foo bar').is_snake_case()
False
Return type:bool
is_snake_case_file_name()

Is true when string is underscore-delimited lowercase file name.

>>> abjad.String('foo_bar').is_snake_case_file_name()
True
>>> abjad.String('foo.bar.blah').is_snake_case_file_name()
False
Return type:bool
is_snake_case_file_name_with_extension()

Is true when string is underscore-delimited lowercase file name with extension.

>>> string = abjad.String('foo_bar.blah')
>>> string.is_snake_case_file_name_with_extension()
True
>>> string = abjad.String('foo.bar.blah')
>>> string.is_snake_case_file_name_with_extension()
False
Return type:bool
is_snake_case_package_name()

Is true when string is underscore-delimited lowercase package name.

>>> string = abjad.String('foo.bar.blah_package')
>>> string.is_snake_case_package_name()
True
>>> string = abjad.String('foo.bar.BlahPackage')
>>> string.is_snake_case_package_name()
False
Return type:bool
is_space_delimited_lowercase()

Is true when string is space-delimited lowercase.

>>> abjad.String('foo bar').is_space_delimited_lowercase()
True
>>> abjad.String('foo_bar').is_space_delimited_lowercase()
False
Return type:bool
is_stylesheet_name()

Is true when string is stylesheet name.

>>> abjad.String('articulations.ily').is_stylesheet_name()
True
>>> abjad.String('Articulations.ily').is_stylesheet_name()
False
>>> abjad.String('articulations.ly').is_stylesheet_name()
False
>>> abjad.String('articulations').is_stylesheet_name()
False
>>> abjad.String('_articulations.ily').is_stylesheet_name()
False
Return type:bool
is_tools_file_name()

Is true when string is tools file name.

>>> abjad.String('beam_specifier.py').is_tools_file_name()
True
>>> abjad.String('BeamSpecifier.py').is_tools_file_name()
True
>>> abjad.String('BeamSpecifier').is_tools_file_name()
False
>>> abjad.String('beamSpecifier.py').is_tools_file_name()
False
>>> abjad.String('Beam_Specifier.py').is_tools_file_name()
False
Return type:bool
is_upper_camel_case()

Is true when string upper camel case.

>>> abjad.String('FooBar').is_upper_camel_case()
True
>>> abjad.String('fooBar').is_upper_camel_case()
False
Return type:bool
(str).isalnum() → bool

Return True if all characters in S are alphanumeric and there is at least one character in S, False otherwise.

(str).isalpha() → bool

Return True if all characters in S are alphabetic and there is at least one character in S, False otherwise.

(str).isdecimal() → bool

Return True if there are only decimal characters in S, False otherwise.

(str).isdigit() → bool

Return True if all characters in S are digits and there is at least one character in S, False otherwise.

(str).isidentifier() → bool

Return True if S is a valid identifier according to the language definition.

Use keyword.iskeyword() to test for reserved identifiers such as “def” and “class”.

(str).islower() → bool

Return True if all cased characters in S are lowercase and there is at least one cased character in S, False otherwise.

(str).isnumeric() → bool

Return True if there are only numeric characters in S, False otherwise.

(str).isprintable() → bool

Return True if all characters in S are considered printable in repr() or S is empty, False otherwise.

(str).isspace() → bool

Return True if all characters in S are whitespace and there is at least one character in S, False otherwise.

(str).istitle() → bool

Return True if S is a titlecased string and there is at least one character in S, i.e. upper- and titlecase characters may only follow uncased characters and lowercase characters only cased ones. Return False otherwise.

(str).isupper() → bool

Return True if all cased characters in S are uppercase and there is at least one cased character in S, False otherwise.

(str).join(iterable) → str

Return a string which is the concatenation of the strings in the iterable. The separator between elements is S.

(str).ljust(width[, fillchar]) → str

Return S left-justified in a Unicode string of length width. Padding is done using the specified fill character (default is a space).

(str).lower() → str

Return a copy of the string S converted to lowercase.

(str).lstrip([chars]) → str

Return a copy of the string S with leading whitespace removed. If chars is given and not None, remove characters in chars instead.

match_word_starts(words)

Matches word starts.

>>> string = abjad.String('StringQuartetScoreTemplate')
>>> string.match_word_starts(['Str', 'Quar', 'Temp'])
True
>>> string.match_word_starts(['S', 'Q', 'S', 'T'])
True
>>> string.match_word_starts(['Quartet'])
True
>>> string.match_word_starts(['Q'])
True
>>> string = abjad.String('StringQuartetScoreTemplate')
>>> string.match_word_starts(['Quar', 'Str'])
False
>>> string.match_word_starts(['uartet'])
False

REGRESSION:

>>> string = abjad.String('IOManager')
>>> string.match_word_starts(['I', 'O'])
True
>>> string = abjad.String('StringQuartetScoreTemplate')
>>> string.match_word_starts(['S', 'Q', 'S', 'T', 'T'])
False
>>> string = abjad.String('AcciaccaturaSpecifier.py')
>>> string.match_word_starts(['A', 'S', 'S'])
False
Return type:bool
(str).partition(sep) -> (head, sep, tail)

Search for the separator sep in S, and return the part before it, the separator itself, and the part after it. If the separator is not found, return S and two empty strings.

pluralize(count=None)

Pluralizes English string.

Changes terminal -y to -ies:

>>> abjad.String('catenary').pluralize()
'catenaries'

Adds -es to terminal -s, -sh, -x and -z:

>>> abjad.String('brush').pluralize()
'brushes'

Adds -s to all other strings:

>>> abjad.String('shape').pluralize()
'shapes'

Does not pluralize when count is 1:

>>> abjad.String('shape').pluralize(count=1)
'shape'
Return type:String
remove_zfill()

Removes zfill from numbers in string.

>>> abjad.String('Horn1').remove_zfill()
'Horn1'
>>> abjad.String('Horn01').remove_zfill()
'Horn1'
>>> abjad.String('Horn001').remove_zfill()
'Horn1'
Return type:String
(str).replace(old, new[, count]) → str

Return a copy of S with all occurrences of substring old replaced by new. If the optional argument count is given, only the first count occurrences are replaced.

(str).rfind(sub[, start[, end]]) → int

Return the highest index in S where substring sub is found, such that sub is contained within S[start:end]. Optional arguments start and end are interpreted as in slice notation.

Return -1 on failure.

(str).rindex(sub[, start[, end]]) → int

Return the highest index in S where substring sub is found, such that sub is contained within S[start:end]. Optional arguments start and end are interpreted as in slice notation.

Raises ValueError when the substring is not found.

(str).rjust(width[, fillchar]) → str

Return S right-justified in a string of length width. Padding is done using the specified fill character (default is a space).

(str).rpartition(sep) -> (head, sep, tail)

Search for the separator sep in S, starting at the end of S, and return the part before it, the separator itself, and the part after it. If the separator is not found, return two empty strings and S.

(str).rsplit(sep=None, maxsplit=-1) → list of strings

Return a list of the words in S, using sep as the delimiter string, starting at the end of the string and working to the front. If maxsplit is given, at most maxsplit splits are done. If sep is not specified, any whitespace string is a separator.

(str).rstrip([chars]) → str

Return a copy of the string S with trailing whitespace removed. If chars is given and not None, remove characters in chars instead.

segment_letter()

Gets segment letter.

>>> abjad.String('_').segment_letter()
'_'
>>> abjad.String('_1').segment_letter()
'_'
>>> abjad.String('_12').segment_letter()
'_'
>>> abjad.String('A').segment_letter()
'A'
>>> abjad.String('A1').segment_letter()
'A'
>>> abjad.String('A12').segment_letter()
'A'
>>> abjad.String('AB').segment_letter()
'AB'
>>> abjad.String('AB1').segment_letter()
'AB'
>>> abjad.String('AB12').segment_letter()
'AB'
segment_rank()

Gets segment index.

>>> abjad.String('_').segment_rank()
0
>>> abjad.String('_1').segment_rank()
1
>>> abjad.String('_12').segment_rank()
12
>>> abjad.String('A').segment_rank()
0
>>> abjad.String('A1').segment_rank()
1
>>> abjad.String('A12').segment_rank()
12
>>> abjad.String('AB').segment_rank()
0
>>> abjad.String('AB1').segment_rank()
1
>>> abjad.String('AB12').segment_rank()
12
(str).split(sep=None, maxsplit=-1) → list of strings

Return a list of the words in S, using sep as the delimiter string. If maxsplit is given, at most maxsplit splits are done. If sep is not specified or is None, any whitespace string is a separator and empty strings are removed from the result.

(str).splitlines([keepends]) → list of strings

Return a list of the lines in S, breaking at line boundaries. Line breaks are not included in the resulting list unless keepends is given and true.

(str).startswith(prefix[, start[, end]]) → bool

Return True if S starts with the specified prefix, False otherwise. With optional start, test S beginning at that position. With optional end, stop comparing S at that position. prefix can also be a tuple of strings to try.

(str).strip([chars]) → str

Return a copy of the string S with leading and trailing whitespace removed. If chars is given and not None, remove characters in chars instead.

strip_diacritics()

Strips diacritics from string.

>>> string = abjad.String('Dvořák')
>>> print(string)
Dvořák
>>> string.strip_diacritics()
'Dvorak'
Return type:String
strip_roman()

Strips roman numerals from right of string.

>>> abjad.String('Trombone').strip_roman()
'Trombone'
>>> abjad.String('TromboneI').strip_roman()
'Trombone'
>>> abjad.String('TromboneII').strip_roman()
'Trombone'
>>> abjad.String('TromboneIII').strip_roman()
'Trombone'
>>> abjad.String('TromboneIV').strip_roman()
'Trombone'
Return type:String
(str).swapcase() → str

Return a copy of S with uppercase characters converted to lowercase and vice versa.

(str).title() → str

Return a titlecased version of S, i.e. words start with title case characters, all remaining cased characters have lower case.

to_accent_free_snake_case()

Changes string to accent-free snake case.

>>> abjad.String('Déja vu').to_accent_free_snake_case()
'deja_vu'
Return type:String
to_dash_case()

Changes string to dash case.

>>> abjad.String('scale degrees 4 and 5').to_dash_case()
'scale-degrees-4-and-5'
>>> abjad.String('scale_degrees_4_and_5').to_dash_case()
'scale-degrees-4-and-5'
>>> abjad.String('scale-degrees-4-and-5').to_dash_case()
'scale-degrees-4-and-5'
>>> abjad.String('ScaleDegrees4And5').to_dash_case()
'scale-degrees-4-and-5'
Return type:String
to_lower_camel_case()

Changes string to lower camel case.

>>> abjad.String('scale degrees 4 and 5').to_lower_camel_case()
'scaleDegrees4And5'
>>> abjad.String('scale_degrees_4_and_5').to_lower_camel_case()
'scaleDegrees4And5'
>>> abjad.String('scale-degrees-4-and-5').to_lower_camel_case()
'scaleDegrees4And5'
>>> abjad.String('ScaleDegrees4And5').to_lower_camel_case()
'scaleDegrees4And5'
Return type:String
to_segment_lilypond_identifier()

Changes string to segment LilyPond identifier.

>>> abjad.String('_').to_segment_lilypond_identifier()
'i'
>>> abjad.String('_1').to_segment_lilypond_identifier()
'i_a'
>>> abjad.String('_2').to_segment_lilypond_identifier()
'i_b'
>>> abjad.String('A').to_segment_lilypond_identifier()
'A'
>>> abjad.String('A1').to_segment_lilypond_identifier()
'A_a'
>>> abjad.String('A2').to_segment_lilypond_identifier()
'A_b'
>>> abjad.String('B').to_segment_lilypond_identifier()
'B'
>>> abjad.String('B1').to_segment_lilypond_identifier()
'B_a'
>>> abjad.String('B2').to_segment_lilypond_identifier()
'B_b'
>>> abjad.String('AA').to_segment_lilypond_identifier()
'AA'
>>> abjad.String('AA1').to_segment_lilypond_identifier()
'AA_a'
>>> abjad.String('AA2').to_segment_lilypond_identifier()
'AA_b'
Return type:String
to_shout_case()

Changes string to shout case.

>>> abjad.String('scale degrees 4 and 5').to_shout_case()
'SCALE_DEGREES_4_AND_5'
>>> abjad.String('scale_degrees_4_and_5').to_shout_case()
'SCALE_DEGREES_4_AND_5'
>>> abjad.String('scale-degrees-4-and-5').to_shout_case()
'SCALE_DEGREES_4_AND_5'
>>> abjad.String('ScaleDegrees4And5').to_shout_case()
'SCALE_DEGREES_4_AND_5'
Return type:String
to_snake_case()

Changes string to snake case.

>>> abjad.String('scale degrees 4 and 5').to_snake_case()
'scale_degrees_4_and_5'
>>> abjad.String('scale_degrees_4_and_5').to_snake_case()
'scale_degrees_4_and_5'
>>> abjad.String('scale-degrees-4-and-5').to_snake_case()
'scale_degrees_4_and_5'
>>> abjad.String('ScaleDegrees4And5').to_snake_case()
'scale_degrees_4_and_5'
Return type:String
to_space_delimited_lowercase()

Changes string to space-delimited lowercase.

>>> abjad.String('LogicalTie').to_space_delimited_lowercase()
'logical tie'
>>> abjad.String('logical_tie').to_space_delimited_lowercase()
'logical tie'
>>> abjad.String('logical tie').to_space_delimited_lowercase()
'logical tie'
>>> abjad.String('').to_space_delimited_lowercase()
''
Return type:String
to_upper_camel_case()

Changes string to upper camel case.

>>> abjad.String('scale degrees 4 and 5').to_upper_camel_case()
'ScaleDegrees4And5'
>>> abjad.String('scale_degrees_4_and_5').to_upper_camel_case()
'ScaleDegrees4And5'
>>> abjad.String('scale-degrees-4-and-5').to_upper_camel_case()
'ScaleDegrees4And5'
>>> abjad.String('ScaleDegrees4And5').to_upper_camel_case()
'ScaleDegrees4And5'
Return type:String
(str).translate(table) → str

Return a copy of the string S in which each character has been mapped through the given translation table. The table must implement lookup/indexing via __getitem__, for instance a dictionary or list, mapping Unicode ordinals to Unicode ordinals, strings, or None. If this operation raises LookupError, the character is left untouched. Characters mapped to None are deleted.

(str).upper() → str

Return a copy of S converted to uppercase.

(str).zfill(width) → str

Pad a numeric string S with zeros on the left, to fill a field of the specified width. The string S is never truncated.


Class & static methods

static base_26(n)

Gets base-26 representation of nonnegative integer n.

Parameters:n (int) – integer.
>>> abjad.String.base_26(1)
'A'
>>> abjad.String.base_26(2)
'B'
>>> abjad.String.base_26(3)
'C'
>>> abjad.String.base_26(26)
'Z'
>>> abjad.String.base_26(27)
'AA'
>>> abjad.String.base_26(28)
'AB'
>>> abjad.String.base_26(52)
'AZ'
>>> abjad.String.base_26(53)
'BA'
>>> abjad.String.base_26(54)
'BB'
>>> abjad.String.base_26(78)
'BZ'
>>> abjad.String.base_26(79)
'CA'
>>> abjad.String.base_26(80)
'CB'
Return type:String
static is_string(argument)

Is true when argument is a string.

>>> abjad.String.is_string('Allegro')
True
>>> abjad.String.is_string('')
True
>>> abjad.String.is_string(99)
False
Return type:bool
static (str).maketrans()

Return a translation table usable for str.translate().

If there is only one argument, it must be a dictionary mapping Unicode ordinals (integers) or characters to Unicode ordinals, strings or None. Character keys will be then converted to ordinals. If there are two arguments, they must be strings of equal length, and in the resulting dictionary, each character in x will be mapped to the character at the same position in y. If there is a third argument, it must be a string, whose characters will be mapped to None in the result.

static match_strings(strings, pattern)

Matches pattern against strings.

>>> strings = [
...     'AcciaccaturaSpecifier.py',
...     'AnchorCommand.py',
...     'ArpeggiationSpacingSpecifier.py',
...     'AttachCommand.py',
...     'ChordalSpacingSpecifier.py',
...     ]
>>> abjad.String.match_strings(strings, 'A')
[]
>>> for i in abjad.String.match_strings(strings, 'At'):
...     strings[i]
'AttachCommand.py'
>>> for i in abjad.String.match_strings(strings, 'AtC'):
...     strings[i]
'AttachCommand.py'
>>> for i in abjad.String.match_strings(strings, 'ASS'):
...     strings[i]
'ArpeggiationSpacingSpecifier.py'
>>> for i in abjad.String.match_strings(strings, 'AC'):
...     strings[i]
'AnchorCommand.py'
'AttachCommand.py'
>>> for i in abjad.String.match_strings(strings, '.py'):
...     strings[i]
'AcciaccaturaSpecifier.py'
'AnchorCommand.py'
'ArpeggiationSpacingSpecifier.py'
'AttachCommand.py'
'ChordalSpacingSpecifier.py'
>>> abjad.String.match_strings(strings, '@AC')
[]

REGRESSION:

>>> abjad.String.match_strings(strings, '||')
[]
>>> strings = ['_allegro', '-allegro', '.allegro', 'allegro']
>>> for i in abjad.String.match_strings(strings, '_al'):
...     strings[i]
'_allegro'
>>> for i in abjad.String.match_strings(strings, '-al'):
...     strings[i]
'-allegro'
>>> for i in abjad.String.match_strings(strings, '.al'):
...     strings[i]
'.allegro'
>>> for i in abjad.String.match_strings(strings, 'egro'):
...     strings[i]
'_allegro'
'-allegro'
'.allegro'
'allegro'
Return type:List[int]
static normalize(argument, indent=None)

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:String
static sort_roman(strings)

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']
Return type:List[String]
static sort_segment_names(strings)

Sorts segment name strings.

>>> strings = ['AA', 'Z', '_11', '_9']
>>> abjad.String.sort_segment_names(strings)
['_9', '_11', 'Z', 'AA']
Return type:List[String]
static to_bidirectional_direction_string(argument)

Changes argument to bidirectional direction string.

>>> abjad.String.to_bidirectional_direction_string('^')
'Up'
>>> abjad.String.to_bidirectional_direction_string('_')
'Down'
>>> abjad.String.to_bidirectional_direction_string(1)
'Up'
>>> abjad.String.to_bidirectional_direction_string(-1)
'Down'
Return type:String
static to_bidirectional_lilypond_symbol(argument)

Changes argument to bidirectional LilyPond symbol.

>>> abjad.String.to_bidirectional_lilypond_symbol(abjad.Up)
'^'
>>> abjad.String.to_bidirectional_lilypond_symbol(abjad.Down)
'_'
>>> abjad.String.to_bidirectional_lilypond_symbol(1)
'^'
>>> abjad.String.to_bidirectional_lilypond_symbol(-1)
'_'
Return type:String
static to_indicator_stem(indicator)

Changes indicator to stem.

>>> abjad.String.to_indicator_stem(abjad.Clef('alto'))
'CLEF'
>>> abjad.String.to_indicator_stem(abjad.Clef('treble'))
'CLEF'
>>> abjad.String.to_indicator_stem(abjad.Dynamic('f'))
'DYNAMIC'
>>> abjad.String.to_indicator_stem(abjad.Cello())
'INSTRUMENT'
>>> abjad.String.to_indicator_stem(abjad.Violin())
'INSTRUMENT'
>>> metronome_mark = abjad.MetronomeMark((1, 4), 58)
>>> abjad.String.to_indicator_stem(metronome_mark)
'METRONOME_MARK'
Return type:String
static to_tridirectional_direction_string(argument)

Changes argument to tridirectional direction string.

>>> abjad.String.to_tridirectional_direction_string('^')
'Up'
>>> abjad.String.to_tridirectional_direction_string('-')
'Center'
>>> abjad.String.to_tridirectional_direction_string('_')
'Down'
>>> abjad.String.to_tridirectional_direction_string(1)
'Up'
>>> abjad.String.to_tridirectional_direction_string(0)
'Center'
>>> abjad.String.to_tridirectional_direction_string(-1)
'Down'

Returns none when argument is none:

>>> abjad.String.to_tridirectional_direction_string(None) is None
True
Return type:Optional[String]
static to_tridirectional_lilypond_symbol(argument)

Changes argument to tridirectional LilyPond symbol.

>>> abjad.String.to_tridirectional_lilypond_symbol(abjad.Up)
'^'
>>> abjad.String.to_tridirectional_lilypond_symbol('center')
'-'
>>> 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
Return type:Optional[String]
static to_tridirectional_ordinal_constant(argument)

Changes argument to tridirectional ordinal constant.

>>> abjad.String.to_tridirectional_ordinal_constant('^')
Up
>>> abjad.String.to_tridirectional_ordinal_constant('_')
Down
>>> abjad.String.to_tridirectional_ordinal_constant(1)
Up
>>> abjad.String.to_tridirectional_ordinal_constant(-1)
Down
>>> abjad.String.to_tridirectional_ordinal_constant(abjad.Up)
Up
>>> abjad.String.to_tridirectional_ordinal_constant(abjad.Down)
Down
>>> abjad.String.to_tridirectional_ordinal_constant(abjad.Center)
Center
>>> abjad.String.to_tridirectional_ordinal_constant(None) is None
True
Return type:Union[None, VerticalAlignment, String]