Skip to content

Commit

Permalink
Merge pull request #103 from RedMadRobot/development
Browse files Browse the repository at this point in the history
7.1.0
  • Loading branch information
taflanidi committed Apr 6, 2023
2 parents 528408a + 45c4cb0 commit 5274d6d
Show file tree
Hide file tree
Showing 26 changed files with 420 additions and 209 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,18 @@
# 𝌡Changelog

## 7.1.0

**⤵️ Added:**

* `NumberInputListener`: a `MaskedTextInputListener` allowing to enter currencies and other numbers
* `"".numberOfOccurencesOf(string)`: a helper method to count occurencies of substrings

**🔄 Modified:**

* `CharacterSet.isMember(character:)` made `public`
* `MaskedTextInputListener`: `UITextFieldDelegate` and `UITextViewDelegate` extensions made `open`
* `MaskedTextInputListener.atomicCaretMovement` is now applied everywhere

## 7.0.1

**🔄 Modified:**
Expand Down
2 changes: 1 addition & 1 deletion InputMask.podspec
@@ -1,6 +1,6 @@
Pod::Spec.new do |spec|
spec.name = "InputMask"
spec.version = "7.0.1"
spec.version = "7.1.0"
spec.summary = "InputMask"
spec.description = "User input masking library."
spec.homepage = "https://github.com/RedMadRobot/input-mask-ios"
Expand Down
Expand Up @@ -16,7 +16,7 @@ public enum AffinityCalculationStrategy {
/**
Default strategy.
Uses ```Mask``` built-in mechanism to calculate total affinity between the text and the mask format.
Uses ``Mask`` built-in mechanism to calculate total affinity between the text and the mask format.
For example:
```
Expand Down
Expand Up @@ -10,10 +10,10 @@ import Foundation
/**
### CaretStringIterator
Iterates over CaretString.string characters. Each ```next()``` call returns current character and adjusts iterator
Iterates over CaretString.string characters. Each ``CaretStringIterator/next()`` call returns current character and adjusts iterator
position.
```CaretStringIterator``` is used by the ```Mask``` instance to iterate over the string that should be formatted.
``CaretStringIterator`` is used by the ``Mask`` instance to iterate over the string that should be formatted.
*/
class CaretStringIterator {

Expand All @@ -23,9 +23,9 @@ class CaretStringIterator {
/**
Constructor
- parameter caretString: ```CaretString``` object, over which the iterator is going to iterate.
- parameter caretString: ``CaretString`` object, over which the iterator is going to iterate.
- returns: Initialized ```CaretStringIterator``` pointing at the beginning of provided ```CaretString.string```
- returns: Initialized ``CaretStringIterator`` pointing at the beginning of provided ``CaretString/string``
*/
init(caretString: CaretString) {
self.caretString = caretString
Expand All @@ -51,11 +51,11 @@ class CaretStringIterator {
}

/**
Iterate over the ```CaretString.string```
Iterate over the ``CaretString/string``
- postcondition: Iterator position is moved to the next symbol.
- returns: Current symbol. If the iterator reached the end of the line, returns ```nil```.
- returns: Current symbol. If the iterator reached the end of the line, returns `nil`.
*/
func next() -> Character? {
if self.currentIndex >= self.caretString.string.endIndex {
Expand Down
6 changes: 3 additions & 3 deletions Source/InputMask/InputMask/Classes/Helper/CharacterSet.swift
Expand Up @@ -8,12 +8,12 @@ import Foundation


/**
Utility extension to make ```CharacterSet``` interact with ```Character``` instances.
Utility extension to make ``CharacterSet`` interact with ``Character`` instances.
*/
extension CharacterSet {
public extension CharacterSet {

/**
Implements ```CharacterSet.characterIsMember(:unichar)``` for ```Character``` instances.
Implements ``CharacterSet/characterIsMember(:unichar)`` for ``Character`` instances.
*/
func isMember(character: Character) -> Bool {
let string: String = String(character)
Expand Down
14 changes: 7 additions & 7 deletions Source/InputMask/InputMask/Classes/Helper/Compiler.swift
Expand Up @@ -12,19 +12,19 @@ import Foundation
Creates a sequence of states from the mask format string.
- seealso: ```State``` class.
- seealso: ``State`` class.
- complexity: ```O(formatString.count)``` plus ```FormatSanitizer``` complexity.
- complexity: `O(formatString.count)` plus ``FormatSanitizer`` complexity.
- requires: Format string to contain only flat groups of symbols in ```[]``` and ```{}``` brackets without nested
brackets, like ```[[000]99]```. Also, ```[]``` groups may contain only the specified characters ("0", "9", "A", "a",
"_", "-" and "…"). Square bracket ```[]``` groups cannot contain mixed types of symbols ("0" and "9" with "A" and "a"
- requires: Format string to contain only flat groups of symbols in `[]` and `{}` brackets without nested
brackets, like `[[000]99]`. Also, `[]` groups may contain only the specified characters ("0", "9", "A", "a",
"_", "-" and "…"). Square bracket `[]` groups cannot contain mixed types of symbols ("0" and "9" with "A" and "a"
or "_" and "-").
```Compiler``` object is initialized and ```Compiler.compile(formatString:)``` is called during the ```Mask``` instance
``Compiler`` object is initialized and ``Compiler/compile(formatString:)`` is called during the ``Mask`` instance
initialization.
```Compiler``` uses ```FormatSanitizer``` to prepare ```formatString``` for the compilation.
``Compiler`` uses ``FormatSanitizer`` to prepare `formatString` for the compilation.
*/
public class Compiler {

Expand Down
38 changes: 19 additions & 19 deletions Source/InputMask/InputMask/Classes/Helper/FormatSanitizer.swift
Expand Up @@ -10,25 +10,25 @@ import Foundation
/**
### FormatSanitizer
Sanitizes given ```formatString``` before it's compilation.
Sanitizes given `formatString` before it's compilation.
- complexity: ```O(2*floor(log(n)))```, and switches to ```O(n^2)``` for ```n < 20``` where
```n = formatString.count```
- complexity: `O(2*floor(log(n)))`, and switches to `O(n^2)` for `n < 20` where
`n = formatString.count`
- requires: Format string to contain only flat groups of symbols in ```[]``` and ```{}``` brackets without nested
brackets, like ```[[000]99]```. Square bracket ```[]``` groups may contain mixed types of symbols ("0" and "9" with
"A" and "a" or "_" and "-"), which sanitizer will divide into separate groups. Such that, ```[0000Aa]``` group will
be divided in two groups: ```[0000]``` and ```[Aa]```.
- requires: Format string to contain only flat groups of symbols in `[]` and `{}` brackets without nested
brackets, like `[[000]99]`. Square bracket `[]` groups may contain mixed types of symbols ("0" and "9" with
"A" and "a" or "_" and "-"), which sanitizer will divide into separate groups. Such that, `[0000Aa]` group will
be divided in two groups: `[0000]` and `[Aa]`.
```FormatSanitizer``` is used by ```Compiler``` before format string compilation.
``FormatSanitizer`` is used by ``Compiler`` before format string compilation.
*/
class FormatSanitizer {

/**
Sanitize ```formatString``` before compilation.
Sanitize `formatString` before compilation.
In order to do so, sanitizer splits the string into groups of regular symbols, symbols in square brackets [] and
symbols in curly brackets {}. Then, characters in square brackets are sorted in a way that mandatory symbols go
In order to do so, sanitizer splits the string into groups of regular symbols, symbols in square brackets `[]` and
symbols in curly brackets `{}`. Then, characters in square brackets are sorted in a way that mandatory symbols go
before optional symbols. For instance,
```
a ([0909]) b
Expand All @@ -38,21 +38,21 @@ class FormatSanitizer {
a ([0099]) b
```
Also, ellipsis in square brackets [] is always placed at the end.
Also, ellipsis in square brackets `[]` is always placed at the end.
- complexity: ```O(2*floor(log(n)))```, and switches to ```O(n^2)``` for ```n < 20``` where
```n = formatString.count```
- complexity: `O(2*floor(log(n)))`, and switches to `O(n^2)` for `n < 20` where
`n = formatString.count`
- requires: Format string to contain only flat groups of symbols in ```[]``` and ```{}``` brackets without nested
brackets, like ```[[000]99]```. Square bracket ```[]``` groups may contain mixed types of symbols ("0" and "9" with
"A" and "a" or "_" and "-"), which sanitizer will divide into separate groups. Such that, ```[0000Aa]``` group will
be divided in two groups: ```[0000]``` and ```[Aa]```.
- requires: Format string to contain only flat groups of symbols in `[]` and `{}` brackets without nested
brackets, like `[[000]99]`. Square bracket `[]` groups may contain mixed types of symbols ("0" and "9" with
"A" and "a" or "_" and "-"), which sanitizer will divide into separate groups. Such that, `[0000Aa]` group will
be divided in two groups: `[0000]` and `[Aa]`.
- parameter formatString: mask format string.
- returns: Sanitized format string.
- throws: ```CompilerError``` if ```formatString``` does not conform to the method requirements.
- throws: ``Compiler/CompilerError`` if `formatString` does not conform to the method requirements.
*/
func sanitize(formatString string: String) throws -> String {
try self.checkOpenBraces(string)
Expand Down
17 changes: 12 additions & 5 deletions Source/InputMask/InputMask/Classes/Helper/String.swift
Expand Up @@ -11,12 +11,12 @@ import UIKit


/**
Utility extension for commonly used ```Mask``` operations upon strings.
Utility extension for commonly used ``Mask`` operations upon strings.
*/
public extension String {

/**
A shortcut for ```String(str.reversed())```.
A shortcut for `String(str.reversed())`.
*/
var reversed: String {
return String(self.reversed())
Expand All @@ -27,7 +27,7 @@ public extension String {
- returns: Current string without first character.
- throws: EXC_BAD_INSTRUCTION for empty strings.
- throws: `EXC_BAD_INSTRUCTION` for empty strings.
*/
func truncateFirst() -> String {
return String(self[self.index(after: self.startIndex)...])
Expand Down Expand Up @@ -75,14 +75,14 @@ public extension String {
}

/**
A shortcut for ```str.distance(from: str.startIndex, to: index)```.
A shortcut for `str.distance(from: str.startIndex, to: index)`.
*/
func distanceFromStartIndex(to index: String.Index) -> Int {
return self.distance(from: self.startIndex, to: index)
}

/**
A shortcut for ```str.index(str.startIndex, offsetBy: offset)```.
A shortcut for `str.index(str.startIndex, offsetBy: offset)`.
*/
func startIndex(offsetBy offset: Int) -> String.Index {
return self.index(self.startIndex, offsetBy: offset)
Expand All @@ -95,6 +95,13 @@ public extension String {
return self.components(separatedBy: CharacterSet.decimalDigits.inverted).joined()
}

/**
Count the number of occurences of a substring.
*/
func numberOfOccurencesOf(_ string: String) -> Int {
return self.components(separatedBy: string).count - 1
}

#if !os(macOS) && !os(watchOS)

/**
Expand Down
30 changes: 15 additions & 15 deletions Source/InputMask/InputMask/Classes/Mask.swift
Expand Up @@ -12,10 +12,10 @@ import Foundation
Iterates over user input. Creates formatted strings from it. Extracts value specified by mask format.
Provided mask format string is translated by the ```Compiler``` class into a set of states, which define the formatting
Provided mask format string is translated by the ``Compiler`` class into a set of states, which define the formatting
and value extraction.
- seealso: ```Compiler```, ```State``` and ```CaretString``` classes.
- seealso: ``Compiler``, ``State`` and ``CaretString`` classes.
*/
public class Mask: CustomDebugStringConvertible, CustomStringConvertible {

Expand Down Expand Up @@ -60,7 +60,7 @@ public class Mask: CustomDebugStringConvertible, CustomStringConvertible {
}

/**
Produce a reversed ```Result``` with reversed formatted text (```CaretString```) and reversed extracted value.
Produce a reversed ``Mask/Result`` with reversed formatted text (``CaretString``) and reversed extracted value.
*/
func reversed() -> Result {
return Result(
Expand All @@ -80,11 +80,11 @@ public class Mask: CustomDebugStringConvertible, CustomStringConvertible {
Constructor.
- parameter format: mask format.
- parameter customNotations: a list of custom rules to compile square bracket ```[]``` groups of format symbols.
- parameter customNotations: a list of custom rules to compile square bracket `[]` groups of format symbols.
- returns: Initialized ```Mask``` instance.
- returns: Initialized ``Mask`` instance.
- throws: ```CompilerError``` if format string is incorrect.
- throws: ``Compiler/CompilerError`` if format string is incorrect.
*/
public required init(format: String, customNotations: [Notation] = []) throws {
self.initialState = try Compiler(customNotations: customNotations).compile(formatString: format)
Expand All @@ -93,10 +93,10 @@ public class Mask: CustomDebugStringConvertible, CustomStringConvertible {
/**
Constructor.
Operates over own ```Mask``` cache where initialized ```Mask``` objects are stored under corresponding format key:
```[format : mask]```
Operates over own ``Mask`` cache where initialized ``Mask`` objects are stored under corresponding format key:
`[format : mask]`
- returns: Previously cached ```Mask``` object for requested format string. If such it doesn't exist in cache, the
- returns: Previously cached ``Mask`` object for requested format string. If such it doesn't exist in cache, the
object is constructed, cached and returned.
*/
public class func getOrCreate(withFormat format: String, customNotations: [Notation] = []) throws -> Mask {
Expand All @@ -113,10 +113,10 @@ public class Mask: CustomDebugStringConvertible, CustomStringConvertible {
Check your mask format is valid.
- parameter format: mask format.
- parameter customNotations: a list of custom rules to compile square bracket ```[]``` groups of format symbols.
- parameter customNotations: a list of custom rules to compile square bracket `[]` groups of format symbols.
- returns: ```true``` if this format coupled with custom notations will compile into a working ```Mask``` object.
Otherwise ```false```.
- returns: `true` if this format coupled with custom notations will compile into a working ``Mask`` object.
Otherwise `false`.
*/
public class func isValid(format: String, customNotations: [Notation] = []) -> Bool {
return nil != (try? self.init(format: format, customNotations: customNotations))
Expand Down Expand Up @@ -300,10 +300,10 @@ public class Mask: CustomDebugStringConvertible, CustomStringConvertible {

/**
While scanning through the input string in the `.apply(…)` method, the mask builds a graph of autocompletion steps.
This graph accumulates the results of `.autocomplete()` calls for each consecutive `State`, acting as a `stack` of
`Next` object instances.
This graph accumulates the results of `.autocomplete()` calls for each consecutive ``State``, acting as a `stack` of
``Next`` object instances.
Each time the `State` returns `null` for its `.autocomplete()`, the graph resets empty.
Each time the ``State`` returns `null` for its `.autocomplete()`, the graph resets empty.
*/
private struct AutocompletionStack {
private var stack = [Next]()
Expand Down
10 changes: 5 additions & 5 deletions Source/InputMask/InputMask/Classes/Model/CaretString.swift
Expand Up @@ -25,9 +25,9 @@ public struct CaretString: CustomDebugStringConvertible, CustomStringConvertible
public let caretPosition: String.Index

/**
When ```Mask``` puts additional characters at caret position, the caret moves in this direction.
When ``Mask`` puts additional characters at caret position, the caret moves in this direction.
Caret usually has a ```.forward``` gravity, unless this ```CaretString``` is a result of deletion/backspacing.
Caret usually has a ``CaretGravity-swift.enum/forward(autocomplete:)`` gravity, unless this ``CaretString`` is a result of deletion/backspacing.
*/
public let caretGravity: CaretGravity

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

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

/**
When ```Mask``` puts additional characters at caret position, the caret moves in this direction.
When ``Mask`` puts additional characters at caret position, the caret moves in this direction.
*/
public enum CaretGravity: Equatable {
/**
Expand Down

0 comments on commit 5274d6d

Please sign in to comment.