Skip to content
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

Terminated due to memory issue on version 1.2.2 #17

Open
evertoncunha opened this issue Sep 15, 2017 · 5 comments
Open

Terminated due to memory issue on version 1.2.2 #17

evertoncunha opened this issue Sep 15, 2017 · 5 comments

Comments

@evertoncunha
Copy link

I'm getting "terminated due to memory issue", on version 1.2.2. It's working fine on v1.2.1.

static func maskTitle(readable: String) -> String {
    //let pattern = "(\\d{5}\\.\\d{5} )(\\d{5}\\.\\d{6} )(\\d{5}\\.\\d{6} )(\\d{1} ).*"

    var mask: String = ""

    let count = readable.characters.count
    if count >= 6 {
      mask += "(\\d{5})\\."
    }
    if count >= 11 {
      mask += "(\\d{5}) "
    }
    if count >= 16 {
      mask += "(\\d{5})\\."
    }
    if count >= 22 {
      mask += "(\\d{6}) "
    }
    if count >= 27 {
      mask += "(\\d{5})\\."
    }
    if count >= 33 {
      mask += "(\\d{6}) "
    }
    if count >= 34 {
      mask += "(\\d{1}) "
    }
    mask += "(.*)"

    return NSStringMask.maskString(readable, withPattern: mask) ?? ""
  }

You can try to pass any value, like maskTitle(readable: "1")

@fjcaetano
Copy link
Owner

What are you trying to accomplish with the (.*) at the end? Could you provide an example of a valid formatted string for your patter?

@evertoncunha
Copy link
Author

evertoncunha commented Sep 22, 2017

It's a pattern for 🇧🇷 barcode payments while you type. Example:
55555
55555.5
55555.55555
55555.55555 5
55555.55555 55555.666666 55555.666666 1 00000000000014

The (.*) at the end is to accept any number after any case of the pattern.

@fjcaetano
Copy link
Owner

You really shouldn't have a group that captures and formats without a limited count. It does fall into an infinite loop in the do-while in [NSStringMask validCharactersForString:(NSString*)]. Could you try limiting the characters captured by that (.*)? Also, by using the dot-star pattern, you'd be capturing any characters, not only digits, spaces and dots.

Perhaps there should be a warning or some other verification at execution time for unlimited repetitions patterns.

@evertoncunha
Copy link
Author

I do a "numbers only" filter previous this function. But the strange thing is that it works fine at version 1.2.1. I'll stick with the previous version then 🤔 .

@fjcaetano
Copy link
Owner

That is super weird. I couldn't see anything obvious that might have broken it. I'll get back to this when I get the chance, so I'll leave your issue open for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants