Modification operations on strings #
This file contains operations on strings which modify the string, like set or map.
There will usually not be a String.Slice version of these operations.
Replaces the character at a specified position in a string with a new character.
If both the replacement character and the replaced character are 7-bit ASCII characters and the string is not shared, then it is updated in-place and not copied.
Examples:
("abc".pos ⟨1⟩ (by decide)).set 'B' (by decide) = "aBc"("L∃∀N".pos ⟨4⟩ (by decide)).set 'X' (by decide) = "L∃XN"
Equations
- One or more equations did not get rendered due to their size.
Instances For
Given a valid position in a string, obtain the corresponding position after setting a character on that string, provided that the position was before the changed position.
Instances For
Replaces the character at position p in the string s with the result of applying f to that
character.
If both the replacement character and the replaced character are 7-bit ASCII characters and the string is not shared, then it is updated in-place and not copied.
Examples:
("abc".pos ⟨1⟩ (by decide)).modify Char.toUpper (by decide) = "aBc"
Instances For
Given a valid position in a string, obtain the corresponding position after modifying a character in that string, provided that the position was before the changed position.
Equations
- q.toModifyOfLE p f hp hpq = { offset := q.offset, isValid := ⋯ }
Instances For
The position just after the position that was modified in a ValidPos.modify call.
Equations
- p.pastModify f hp = p.pastSet (f (p.get hp)) hp
Instances For
Replaces the character at a specified position in a string with a new character. If the position is invalid, the string is returned unchanged.
If both the replacement character and the replaced character are 7-bit ASCII characters and the string is not shared, then it is updated in-place and not copied.
This is a legacy function. The recommended alternative is String.ValidPos.set, combined with
String.pos or another means of obtaining a String.ValidPos.
Examples:
"abc".set ⟨1⟩ 'B' = "aBc""abc".set ⟨3⟩ 'D' = "abc""L∃∀N".set ⟨4⟩ 'X' = "L∃XN""L∃∀N".set ⟨2⟩ 'X' = "L∃∀N"because'∃'is a multi-byte character, so the byte index2is an invalid position.
Equations
- String.Pos.Raw.set x✝² x✝¹ x✝ = String.ofList (String.Pos.Raw.utf8SetAux x✝ x✝².toList 0 x✝¹)
Instances For
Equations
- x✝².set x✝¹ x✝ = String.ofList (String.Pos.Raw.utf8SetAux x✝ x✝².toList 0 x✝¹)
Instances For
Replaces the character at position p in the string s with the result of applying f to that
character. If p is an invalid position, the string is returned unchanged.
If both the replacement character and the replaced character are 7-bit ASCII characters and the string is not shared, then it is updated in-place and not copied.
This is a legacy function. The recommended alternative is String.ValidPos.set, combined with
String.pos or another means of obtaining a String.ValidPos.
Examples:
"abc".modify ⟨1⟩ Char.toUpper = "aBc""abc".modify ⟨3⟩ Char.toUpper = "abc"
Equations
- String.Pos.Raw.modify s i f = String.Pos.Raw.set s i (f (String.Pos.Raw.get s i))
Instances For
Replaces the character at position p in the string s with the result of applying f to that
character. If p is an invalid position, the string is returned unchanged.
If both the replacement character and the replaced character are 7-bit ASCII characters and the string is not shared, then it is updated in-place and not copied.
This is a legacy function. The recommended alternative is String.ValidPos.set, combined with
String.pos or another means of obtaining a String.ValidPos.
Examples:
"abc".modify ⟨1⟩ Char.toUpper = "aBc""abc".modify ⟨3⟩ Char.toUpper = "abc"
Equations
- s.modify i f = String.Pos.Raw.set s i (f (String.Pos.Raw.get s i))
Instances For
Equations
- String.mapAux f s p = if h : p = s.endValidPos then s else String.mapAux f (p.modify f h) (p.pastModify f h)
Instances For
Applies the function f to every character in a string, returning a string that contains the
resulting characters.
Examples:
"abc123".map Char.toUpper = "ABC123""".map Char.toUpper = ""
Equations
- String.map f s = String.mapAux f s s.startValidPos
Instances For
Replaces each character in s with the result of applying Char.toUpper to it.
Char.toUpper has no effect on characters outside of the range 'a'–'z'.
Examples:
Equations
Instances For
Replaces each character in s with the result of applying Char.toLower to it.
Char.toLower has no effect on characters outside of the range 'A'–'Z'.
Examples:
Equations
Instances For
Replaces the first character in s with the result of applying Char.toUpper to it. Returns the
empty string if the string is empty.
Char.toUpper has no effect on characters outside of the range 'a'–'z'.
Examples:
"orange".capitalize = "Orange""ORANGE".capitalize = "ORANGE""".capitalize = ""
Equations
- s.capitalize = String.Pos.Raw.set s 0 (String.Pos.Raw.get s 0).toUpper
Instances For
Equations
Instances For
Replaces the first character in s with the result of applying Char.toLower to it. Returns the
empty string if the string is empty.
Char.toLower has no effect on characters outside of the range 'A'–'Z'.
Examples:
"Orange".decapitalize = "orange""ORANGE".decapitalize = "oRANGE""".decapitalize = ""
Equations
- s.decapitalize = String.Pos.Raw.set s 0 (String.Pos.Raw.get s 0).toLower