Naddiseo/dart-sprintf

Formatter cannot recognize \% as string

Closed this issue · 3 comments

Hi there,

In case that you want to create string following this pattern:
String a = 'For %s\% during %s years';
where \% should be percentage character, the library reports an error:
type 'String' is not a subtype of type 'int'
However, if i omit the sign, everything works fine.

I am using version
sprintf: "^4.0.0"

Please let me know if you need any additional information.

thanks

So, looking into this, it's actually behaving as expected. For literal %, you specify it as %%[1]. In your example string it's seeing % d as the specifier.

[1] http://www.cplusplus.com/reference/cstdio/printf/

Thanks, this really helped me.
I would suggest to make \% to be valid string since it is the way that Dart recognise the percentage sign and probably somebody else will assume that you have followed Dart 's standard and not c/cpp.

thanks again :)

Unfortunately, that's out of my control since the escape sequences are handled before they're passed to dart-sprintf:

main() {
  //          0123456
  String a = 'For %s\% during %s years';
  print(a[6]); // should print "\" not "%"
  print(a); // does not contain the "\"
}