Skip to content

Commit 5274d6d

Browse files
authored
Merge pull request #103 from RedMadRobot/development
7.1.0
2 parents 528408a + 45c4cb0 commit 5274d6d

26 files changed

+420
-209
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
# 𝌡Changelog
22

3+
## 7.1.0
4+
5+
**⤵️ Added:**
6+
7+
* `NumberInputListener`: a `MaskedTextInputListener` allowing to enter currencies and other numbers
8+
* `"".numberOfOccurencesOf(string)`: a helper method to count occurencies of substrings
9+
10+
**🔄 Modified:**
11+
12+
* `CharacterSet.isMember(character:)` made `public`
13+
* `MaskedTextInputListener`: `UITextFieldDelegate` and `UITextViewDelegate` extensions made `open`
14+
* `MaskedTextInputListener.atomicCaretMovement` is now applied everywhere
15+
316
## 7.0.1
417

518
**🔄 Modified:**

InputMask.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |spec|
22
spec.name = "InputMask"
3-
spec.version = "7.0.1"
3+
spec.version = "7.1.0"
44
spec.summary = "InputMask"
55
spec.description = "User input masking library."
66
spec.homepage = "https://github.com/RedMadRobot/input-mask-ios"

Source/InputMask/InputMask/Classes/Helper/AffinityCalculationStrategy.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public enum AffinityCalculationStrategy {
1616
/**
1717
Default strategy.
1818

19-
Uses ```Mask``` built-in mechanism to calculate total affinity between the text and the mask format.
19+
Uses ``Mask`` built-in mechanism to calculate total affinity between the text and the mask format.
2020

2121
For example:
2222
```

Source/InputMask/InputMask/Classes/Helper/CaretStringIterator.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ import Foundation
1010
/**
1111
### CaretStringIterator
1212

13-
Iterates over CaretString.string characters. Each ```next()``` call returns current character and adjusts iterator
13+
Iterates over CaretString.string characters. Each ``CaretStringIterator/next()`` call returns current character and adjusts iterator
1414
position.
1515

16-
```CaretStringIterator``` is used by the ```Mask``` instance to iterate over the string that should be formatted.
16+
``CaretStringIterator`` is used by the ``Mask`` instance to iterate over the string that should be formatted.
1717
*/
1818
class CaretStringIterator {
1919

@@ -23,9 +23,9 @@ class CaretStringIterator {
2323
/**
2424
Constructor
2525

26-
- parameter caretString: ```CaretString``` object, over which the iterator is going to iterate.
26+
- parameter caretString: ``CaretString`` object, over which the iterator is going to iterate.
2727

28-
- returns: Initialized ```CaretStringIterator``` pointing at the beginning of provided ```CaretString.string```
28+
- returns: Initialized ``CaretStringIterator`` pointing at the beginning of provided ``CaretString/string``
2929
*/
3030
init(caretString: CaretString) {
3131
self.caretString = caretString
@@ -51,11 +51,11 @@ class CaretStringIterator {
5151
}
5252

5353
/**
54-
Iterate over the ```CaretString.string```
54+
Iterate over the ``CaretString/string``
5555

5656
- postcondition: Iterator position is moved to the next symbol.
5757

58-
- returns: Current symbol. If the iterator reached the end of the line, returns ```nil```.
58+
- returns: Current symbol. If the iterator reached the end of the line, returns `nil`.
5959
*/
6060
func next() -> Character? {
6161
if self.currentIndex >= self.caretString.string.endIndex {

Source/InputMask/InputMask/Classes/Helper/CharacterSet.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ import Foundation
88

99

1010
/**
11-
Utility extension to make ```CharacterSet``` interact with ```Character``` instances.
11+
Utility extension to make ``CharacterSet`` interact with ``Character`` instances.
1212
*/
13-
extension CharacterSet {
13+
public extension CharacterSet {
1414

1515
/**
16-
Implements ```CharacterSet.characterIsMember(:unichar)``` for ```Character``` instances.
16+
Implements ``CharacterSet/characterIsMember(:unichar)`` for ``Character`` instances.
1717
*/
1818
func isMember(character: Character) -> Bool {
1919
let string: String = String(character)

Source/InputMask/InputMask/Classes/Helper/Compiler.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@ import Foundation
1212

1313
Creates a sequence of states from the mask format string.
1414

15-
- seealso: ```State``` class.
15+
- seealso: ``State`` class.
1616

17-
- complexity: ```O(formatString.count)``` plus ```FormatSanitizer``` complexity.
17+
- complexity: `O(formatString.count)` plus ``FormatSanitizer`` complexity.
1818

19-
- requires: Format string to contain only flat groups of symbols in ```[]``` and ```{}``` brackets without nested
20-
brackets, like ```[[000]99]```. Also, ```[]``` groups may contain only the specified characters ("0", "9", "A", "a",
21-
"_", "-" and "…"). Square bracket ```[]``` groups cannot contain mixed types of symbols ("0" and "9" with "A" and "a"
19+
- requires: Format string to contain only flat groups of symbols in `[]` and `{}` brackets without nested
20+
brackets, like `[[000]99]`. Also, `[]` groups may contain only the specified characters ("0", "9", "A", "a",
21+
"_", "-" and "…"). Square bracket `[]` groups cannot contain mixed types of symbols ("0" and "9" with "A" and "a"
2222
or "_" and "-").
2323

24-
```Compiler``` object is initialized and ```Compiler.compile(formatString:)``` is called during the ```Mask``` instance
24+
``Compiler`` object is initialized and ``Compiler/compile(formatString:)`` is called during the ``Mask`` instance
2525
initialization.
2626

27-
```Compiler``` uses ```FormatSanitizer``` to prepare ```formatString``` for the compilation.
27+
``Compiler`` uses ``FormatSanitizer`` to prepare `formatString` for the compilation.
2828
*/
2929
public class Compiler {
3030

Source/InputMask/InputMask/Classes/Helper/FormatSanitizer.swift

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,25 @@ import Foundation
1010
/**
1111
### FormatSanitizer
1212

13-
Sanitizes given ```formatString``` before it's compilation.
13+
Sanitizes given `formatString` before it's compilation.
1414

15-
- complexity: ```O(2*floor(log(n)))```, and switches to ```O(n^2)``` for ```n < 20``` where
16-
```n = formatString.count```
15+
- complexity: `O(2*floor(log(n)))`, and switches to `O(n^2)` for `n < 20` where
16+
`n = formatString.count`
1717

18-
- requires: Format string to contain only flat groups of symbols in ```[]``` and ```{}``` brackets without nested
19-
brackets, like ```[[000]99]```. Square bracket ```[]``` groups may contain mixed types of symbols ("0" and "9" with
20-
"A" and "a" or "_" and "-"), which sanitizer will divide into separate groups. Such that, ```[0000Aa]``` group will
21-
be divided in two groups: ```[0000]``` and ```[Aa]```.
18+
- requires: Format string to contain only flat groups of symbols in `[]` and `{}` brackets without nested
19+
brackets, like `[[000]99]`. Square bracket `[]` groups may contain mixed types of symbols ("0" and "9" with
20+
"A" and "a" or "_" and "-"), which sanitizer will divide into separate groups. Such that, `[0000Aa]` group will
21+
be divided in two groups: `[0000]` and `[Aa]`.
2222

23-
```FormatSanitizer``` is used by ```Compiler``` before format string compilation.
23+
``FormatSanitizer`` is used by ``Compiler`` before format string compilation.
2424
*/
2525
class FormatSanitizer {
2626

2727
/**
28-
Sanitize ```formatString``` before compilation.
28+
Sanitize `formatString` before compilation.
2929

30-
In order to do so, sanitizer splits the string into groups of regular symbols, symbols in square brackets [] and
31-
symbols in curly brackets {}. Then, characters in square brackets are sorted in a way that mandatory symbols go
30+
In order to do so, sanitizer splits the string into groups of regular symbols, symbols in square brackets `[]` and
31+
symbols in curly brackets `{}`. Then, characters in square brackets are sorted in a way that mandatory symbols go
3232
before optional symbols. For instance,
3333
```
3434
a ([0909]) b
@@ -38,21 +38,21 @@ class FormatSanitizer {
3838
a ([0099]) b
3939
```
4040

41-
Also, ellipsis in square brackets [] is always placed at the end.
41+
Also, ellipsis in square brackets `[]` is always placed at the end.
4242

43-
- complexity: ```O(2*floor(log(n)))```, and switches to ```O(n^2)``` for ```n < 20``` where
44-
```n = formatString.count```
43+
- complexity: `O(2*floor(log(n)))`, and switches to `O(n^2)` for `n < 20` where
44+
`n = formatString.count`
4545

46-
- requires: Format string to contain only flat groups of symbols in ```[]``` and ```{}``` brackets without nested
47-
brackets, like ```[[000]99]```. Square bracket ```[]``` groups may contain mixed types of symbols ("0" and "9" with
48-
"A" and "a" or "_" and "-"), which sanitizer will divide into separate groups. Such that, ```[0000Aa]``` group will
49-
be divided in two groups: ```[0000]``` and ```[Aa]```.
46+
- requires: Format string to contain only flat groups of symbols in `[]` and `{}` brackets without nested
47+
brackets, like `[[000]99]`. Square bracket `[]` groups may contain mixed types of symbols ("0" and "9" with
48+
"A" and "a" or "_" and "-"), which sanitizer will divide into separate groups. Such that, `[0000Aa]` group will
49+
be divided in two groups: `[0000]` and `[Aa]`.
5050

5151
- parameter formatString: mask format string.
5252

5353
- returns: Sanitized format string.
5454

55-
- throws: ```CompilerError``` if ```formatString``` does not conform to the method requirements.
55+
- throws: ``Compiler/CompilerError`` if `formatString` does not conform to the method requirements.
5656
*/
5757
func sanitize(formatString string: String) throws -> String {
5858
try self.checkOpenBraces(string)

Source/InputMask/InputMask/Classes/Helper/String.swift

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ import UIKit
1111

1212

1313
/**
14-
Utility extension for commonly used ```Mask``` operations upon strings.
14+
Utility extension for commonly used ``Mask`` operations upon strings.
1515
*/
1616
public extension String {
1717

1818
/**
19-
A shortcut for ```String(str.reversed())```.
19+
A shortcut for `String(str.reversed())`.
2020
*/
2121
var reversed: String {
2222
return String(self.reversed())
@@ -27,7 +27,7 @@ public extension String {
2727

2828
- returns: Current string without first character.
2929

30-
- throws: EXC_BAD_INSTRUCTION for empty strings.
30+
- throws: `EXC_BAD_INSTRUCTION` for empty strings.
3131
*/
3232
func truncateFirst() -> String {
3333
return String(self[self.index(after: self.startIndex)...])
@@ -75,14 +75,14 @@ public extension String {
7575
}
7676

7777
/**
78-
A shortcut for ```str.distance(from: str.startIndex, to: index)```.
78+
A shortcut for `str.distance(from: str.startIndex, to: index)`.
7979
*/
8080
func distanceFromStartIndex(to index: String.Index) -> Int {
8181
return self.distance(from: self.startIndex, to: index)
8282
}
8383

8484
/**
85-
A shortcut for ```str.index(str.startIndex, offsetBy: offset)```.
85+
A shortcut for `str.index(str.startIndex, offsetBy: offset)`.
8686
*/
8787
func startIndex(offsetBy offset: Int) -> String.Index {
8888
return self.index(self.startIndex, offsetBy: offset)
@@ -95,6 +95,13 @@ public extension String {
9595
return self.components(separatedBy: CharacterSet.decimalDigits.inverted).joined()
9696
}
9797

98+
/**
99+
Count the number of occurences of a substring.
100+
*/
101+
func numberOfOccurencesOf(_ string: String) -> Int {
102+
return self.components(separatedBy: string).count - 1
103+
}
104+
98105
#if !os(macOS) && !os(watchOS)
99106

100107
/**

Source/InputMask/InputMask/Classes/Mask.swift

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ import Foundation
1212

1313
Iterates over user input. Creates formatted strings from it. Extracts value specified by mask format.
1414

15-
Provided mask format string is translated by the ```Compiler``` class into a set of states, which define the formatting
15+
Provided mask format string is translated by the ``Compiler`` class into a set of states, which define the formatting
1616
and value extraction.
1717

18-
- seealso: ```Compiler```, ```State``` and ```CaretString``` classes.
18+
- seealso: ``Compiler``, ``State`` and ``CaretString`` classes.
1919
*/
2020
public class Mask: CustomDebugStringConvertible, CustomStringConvertible {
2121

@@ -60,7 +60,7 @@ public class Mask: CustomDebugStringConvertible, CustomStringConvertible {
6060
}
6161

6262
/**
63-
Produce a reversed ```Result``` with reversed formatted text (```CaretString```) and reversed extracted value.
63+
Produce a reversed ``Mask/Result`` with reversed formatted text (``CaretString``) and reversed extracted value.
6464
*/
6565
func reversed() -> Result {
6666
return Result(
@@ -80,11 +80,11 @@ public class Mask: CustomDebugStringConvertible, CustomStringConvertible {
8080
Constructor.
8181

8282
- parameter format: mask format.
83-
- parameter customNotations: a list of custom rules to compile square bracket ```[]``` groups of format symbols.
83+
- parameter customNotations: a list of custom rules to compile square bracket `[]` groups of format symbols.
8484

85-
- returns: Initialized ```Mask``` instance.
85+
- returns: Initialized ``Mask`` instance.
8686

87-
- throws: ```CompilerError``` if format string is incorrect.
87+
- throws: ``Compiler/CompilerError`` if format string is incorrect.
8888
*/
8989
public required init(format: String, customNotations: [Notation] = []) throws {
9090
self.initialState = try Compiler(customNotations: customNotations).compile(formatString: format)
@@ -93,10 +93,10 @@ public class Mask: CustomDebugStringConvertible, CustomStringConvertible {
9393
/**
9494
Constructor.
9595

96-
Operates over own ```Mask``` cache where initialized ```Mask``` objects are stored under corresponding format key:
97-
```[format : mask]```
96+
Operates over own ``Mask`` cache where initialized ``Mask`` objects are stored under corresponding format key:
97+
`[format : mask]`
9898

99-
- returns: Previously cached ```Mask``` object for requested format string. If such it doesn't exist in cache, the
99+
- returns: Previously cached ``Mask`` object for requested format string. If such it doesn't exist in cache, the
100100
object is constructed, cached and returned.
101101
*/
102102
public class func getOrCreate(withFormat format: String, customNotations: [Notation] = []) throws -> Mask {
@@ -113,10 +113,10 @@ public class Mask: CustomDebugStringConvertible, CustomStringConvertible {
113113
Check your mask format is valid.
114114

115115
- parameter format: mask format.
116-
- parameter customNotations: a list of custom rules to compile square bracket ```[]``` groups of format symbols.
116+
- parameter customNotations: a list of custom rules to compile square bracket `[]` groups of format symbols.
117117

118-
- returns: ```true``` if this format coupled with custom notations will compile into a working ```Mask``` object.
119-
Otherwise ```false```.
118+
- returns: `true` if this format coupled with custom notations will compile into a working ``Mask`` object.
119+
Otherwise `false`.
120120
*/
121121
public class func isValid(format: String, customNotations: [Notation] = []) -> Bool {
122122
return nil != (try? self.init(format: format, customNotations: customNotations))
@@ -300,10 +300,10 @@ public class Mask: CustomDebugStringConvertible, CustomStringConvertible {
300300

301301
/**
302302
While scanning through the input string in the `.apply(…)` method, the mask builds a graph of autocompletion steps.
303-
This graph accumulates the results of `.autocomplete()` calls for each consecutive `State`, acting as a `stack` of
304-
`Next` object instances.
303+
This graph accumulates the results of `.autocomplete()` calls for each consecutive ``State``, acting as a `stack` of
304+
``Next`` object instances.
305305

306-
Each time the `State` returns `null` for its `.autocomplete()`, the graph resets empty.
306+
Each time the ``State`` returns `null` for its `.autocomplete()`, the graph resets empty.
307307
*/
308308
private struct AutocompletionStack {
309309
private var stack = [Next]()

Source/InputMask/InputMask/Classes/Model/CaretString.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ public struct CaretString: CustomDebugStringConvertible, CustomStringConvertible
2525
public let caretPosition: String.Index
2626

2727
/**
28-
When ```Mask``` puts additional characters at caret position, the caret moves in this direction.
28+
When ``Mask`` puts additional characters at caret position, the caret moves in this direction.
2929

30-
Caret usually has a ```.forward``` gravity, unless this ```CaretString``` is a result of deletion/backspacing.
30+
Caret usually has a ``CaretGravity-swift.enum/forward(autocomplete:)`` gravity, unless this ``CaretString`` is a result of deletion/backspacing.
3131
*/
3232
public let caretGravity: CaretGravity
3333

@@ -36,7 +36,7 @@ public struct CaretString: CustomDebugStringConvertible, CustomStringConvertible
3636

3737
- parameter string: text from the user.
3838
- parameter caretPosition: cursor position from the input text field.
39-
- parameter caretGravity: caret tends to move in this direction during ```Mask``` insertions at caret position.
39+
- parameter caretGravity: caret tends to move in this direction during ``Mask`` insertions at caret position.
4040
*/
4141
public init(string: String, caretPosition: String.Index, caretGravity: CaretGravity) {
4242
self.string = string
@@ -53,7 +53,7 @@ public struct CaretString: CustomDebugStringConvertible, CustomStringConvertible
5353
}
5454

5555
/**
56-
Creates a reversed ```CaretString``` instance with reversed string and corresponding caret position.
56+
Creates a reversed ``CaretString`` instance with reversed string and corresponding caret position.
5757
*/
5858
func reversed() -> CaretString {
5959
let reversedString: String = self.string.reversed
@@ -67,7 +67,7 @@ public struct CaretString: CustomDebugStringConvertible, CustomStringConvertible
6767
}
6868

6969
/**
70-
When ```Mask``` puts additional characters at caret position, the caret moves in this direction.
70+
When ``Mask`` puts additional characters at caret position, the caret moves in this direction.
7171
*/
7272
public enum CaretGravity: Equatable {
7373
/**

0 commit comments

Comments
 (0)