Comments (6)
Hey @AlexisQapa, thanks for your suggestion.
My idea is to add a Pattern Builder entity, allowing things like
let formats: [String] =
Pattern("[AAAA]")
.affineRepeat(min: 3, max: 6, separator: " ")
.suffix("[000]")
.build
// produces:
[
"[AAAA] [AAAA] [AAAA]",
"[AAAA] [AAAA] [AAAA] [AAAA]",
"[AAAA] [AAAA] [AAAA] [AAAA] [AAAA]",
"[AAAA] [AAAA] [AAAA] [AAAA] [AAAA] [AAAA]",
"[AAAA] [AAAA] [AAAA] [AAAA] [AAAA] [AAAA] [000]",
]
Benefits:
First of all, affine formats allow us to have a consistent complete
flag value.
Output Complete
1234 1234 123 False
1234 1234 1234 True
1234 1234 1234 1 False
1234 1234 1234 12 False
1234 1234 1234 123 False
1234 1234 1234 1234 True
Second, this Pattern Builder approach doesn't require the library to go full regular expressions syntax, which is good because I hate the idea.
The only thing is to figure out a usable and practical Pattern Builder interface.
Methods like affineRepeat(β¦)
or suffix(β¦)
are just a shot in the dark, I made them up and I can't imagine any new ones at the moment, so tell me your thoughts.
from input-mask-ios.
Generating all the patterns was my first idea but I didn't knew how to integrate it into the lib. Your builder is definitely a nice solution ! I like how it's just a helper which ppl can opt in opt out
from input-mask-ios.
@AlexisQapa, okay, so let's compose a preliminary interface for this utility.
Once again, I've got no idea what I'm doing, but let's give it a try.
class AffinePattern {
init(format: String)
/// Make a [AAAaaa] group
///
/// - parameter count: number of mandatory letters;
/// - parameter optionalCount: number of optional letters;
///
/// - returns: An `AffinePattern` instance.
class func makeLetters(count: Int, optionalCount: Int = 0) -> AffinePattern
/// Make a [000999] group
///
/// - parameter count: number of mandatory digits;
/// - parameter optionalCount: number of optional digits;
///
/// - returns: An `AffinePattern` instance.
class func makeDigits(count: Int, optionalCount: Int = 0) -> AffinePattern
/// Make a repetitive group.
///
/// - parameter times: number of repetitions; e.g. [3...5]
/// - parameter separator: a string to be inserted in between repeated groups;
///
/// - returns: An `AffinePattern` instance.
///
/// - usage:
/// AffinePattern("[00]").repeat(times: [2..4], separator: " ") // is equal to:
/// [
/// "[00] [00]",
/// "[00] [00] [00]",
/// "[00] [00] [00] [00]",
/// ]
func repeat(times: Range<Int>, separator: String = "") -> AffinePattern
/// For each item in a repetitive group append a suffix.
///
/// - parameter suffix: a string to be appended
///
/// - returns: An `AffinePattern` instance.
///
/// - usage:
/// AffinePattern("[00]").repeat(times: [2..4], separator: " ").appending(suffix: "-[0]") // is equal to:
/// [
/// "[00] [00]-[0]",
/// "[00] [00] [00]-[0]",
/// "[00] [00] [00] [00]-[0]",
/// ]
func appending(suffix: String) -> AffinePattern
/// For each item in a repetitive group insert a prefix.
///
/// - parameter prefix: a string to be inserted
///
/// - returns: An `AffinePattern` instance.
///
/// - usage:
/// AffinePattern("[00]").repeat(times: [2..4], separator: " ").inserting(prefix: "[0]-") // is equal to:
/// [
/// "[0]-[00] [00]",
/// "[0]-[00] [00] [00]",
/// "[0]-[00] [00] [00] [00]",
/// ]
func inserting(prefix: String) -> AffinePattern
/// For the last item in a repetitive group insert a prefix and append a suffix.
///
/// - parameter prefix: a string to be inserted
/// - parameter suffix: a string to be appended
///
/// - returns: An `AffinePattern` instance.
///
/// - usage:
/// AffinePattern("[00]").repeat(times: [2..4], separator: " "). paddingLast(prefix: "[0]-", suffix: "-[000]") // is equal to:
/// [
/// "[00] [00]",
/// "[00] [00] [00]",
/// "[0]-[00] [00] [00] [00]-[000]",
/// ]
func paddingLast(prefix: String, suffix: String) -> AffinePattern
/// For the first item in a repetitive group insert a prefix and append a suffix.
///
/// - parameter prefix: a string to be inserted
/// - parameter suffix: a string to be appended
///
/// - returns: An `AffinePattern` instance.
///
/// - usage:
/// AffinePattern("[00]").repeat(times: [2..4], separator: " "). paddingFirst(prefix: "[0]-", suffix: "-[000]") // is equal to:
/// [
/// "[0]-[00] [00]-[000]",
/// "[00] [00] [00]",
/// "[00] [00] [00] [00]",
/// ]
func paddingFirst(prefix: String, suffix: String) -> AffinePattern
/// Build a repetitive group
var build: [String]
}
Anything missing?
from input-mask-ios.
Seems good to me, I think It would be sufficient for my use case.
I've read that Swift 5 is coming with native support for string regex for your information, might be useful at some point.
from input-mask-ios.
Okay, I'll be adding this new utility in the next library update.
I've read that Swift 5 is coming with native support for string regex for your information, might be useful at some point.
NSRegularExpression.
Not applicable to our library needs, though.
from input-mask-ios.
Hey @AlexisQapa
I wonder if this thing is still needed. Could you please give me a hint?
With the introduction of full-fledged number formatting it seems like this thing might be redundant.
from input-mask-ios.
Related Issues (20)
- can you add tailplaceholder as parameter, like MaskedTexfieldDelegate(primaryFormat: [99] / [99], isTailPlaceholderVisible: true) HOT 3
- Move the list of countries to an external file⦠maybe?
- fix put when primaryMaskFormat "7 ([999])", if we use put("788", textfield) and if string first char is 7 mask will remove it, output: "7 88" HOT 8
- Update the wikis
- Obtain text field value without input-mask HOT 1
- first number of format is wrong with prefix HOT 2
- Being able to use the `UITextField` delegates HOT 11
- First number of mask(#104) HOT 17
- Automatic Caps Lock Activation Issue in MaskedTextField HOT 7
- Install in macOS project HOT 2
- Multiple Swift compiler Errors: * is only available in tvOS 10.0 or newer HOT 2
- IOS Objective-C Programmatically example HOT 1
- [!] Unable to determine Swift version for the following pods HOT 1
- Unable to use with single textField HOT 2
- How to define ${dynamic amount }/month in input mask HOT 1
- How to write uppercased text? HOT 2
- Number Formatting (Thousand Separator) HOT 3
- Poor performance when user types fast HOT 3
- can you make mask template always visible while user input text HOT 2
- My repo
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from input-mask-ios.