-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Question] How do I initially fill in the mask having only symbols for blanks? #114
Comments
Hi @krypt-lx Since I don't have the whole context, I'll assume you've got one of the following scenarios:
In this case, your phone number values will always contain no country codes, thus the Hence, for rendering, you must adapt those values and insert the Imagine you have a
Therefore, the |
It isn't answer the question, though. I boiled down the issue I have to simple example. Basically I have the mask (one which I convert to compatible format in app) and the value from third party via api. It can be any kind of mask for any purpose. So, that it, I need to fill in blanks with given characters and preset it to the user to edit. Nothing more, nothing less. It isn't hard to manually evaluate the characters in the mask and fill blanks in, but I before I do so I want to know if there maybe a proper solution? |
Ah, the third-party masking patterns :D A go-to here is a two-step process. {
"mask": "+1 (###) ### ## ##",
"value": "1234567890"
} The var output = "+1 (###) ### ## ##"
let value = "1234567890"
value.forEach { char in
output.replace("#", with: String(char), maxReplacements: 1)
} As you've said earlier,
—so go ahead and do it. Next, you apply the |
I will add, though, It would be nice if this lib would be able to process its own output (extractedValue). Consider it to be a feature request |
@krypt-lx but you already can. Inherit, override. Everything's |
You missing the point: it is not about what I can and what I can't do, the lib can produce output (containing sufficient amount of data) which it can't handle as input. It looks like the lib is incomplete. |
Hey, let's keep this conversation constructive, please. First of all, describe an expected library behaviour and business features you're trying to achieve. The end goal and the algorithms you'd like to have under the hood. Second, keep in mind that this library occupies the same shelf as the regular expressions. This is a low-level String-operating utility that has no knowledge about the domain semantics whatsoever—and it must not. |
The task:
For example, I have mask "123 [000]" and value "345" and I need to construct value "123 345" and present it to the user. The I'm aware there are reasons to do it in a different way, but like I already said this is the data format I have. I wrote a simple state machine processing mask format, but I rather avoid having unnecessary complex code in the project. |
@krypt-lx my apologies for the delay. I'll be able to roll out an update during this week, I guess. In my head, the use case should be like let format = "123 [000]"
let input = "234"
let result = Mask(
format: format,
turnOnTheFeatureTemporaryName: true
).apply(toText: input).formattedText
→ "123 234" Please let me know if it works for you. P.S. If you happen to come up with a catchy name instead of |
fillInBlanksOnly? wildcardsOnly? matchOnlyWildcards? |
It is not a bugreport, but I question I can't find the answer for:
+1 ([000]) [000] [00] [00]
for example1234567890
, which represents blank characters of the mask (the same value returned inextractedValue
byMask.apply
)If I feed the value into the mask, it will return formatted value "+1 (234) 567 89 0", with complete flag set to false (the first digit was eaten by non-blanked symbol)
How do I properly fill in the mask? What about more complex cases (fixed character in the middle of the mask, for example)?
The text was updated successfully, but these errors were encountered: