Returns True if |string| is in its canonical integer form. The canonical form is such that str(int(string)) == string.
(string)
| 689 | |
| 690 | |
| 691 | def IsStrCanonicalInt(string): |
| 692 | """Returns True if |string| is in its canonical integer form. |
| 693 | |
| 694 | The canonical form is such that str(int(string)) == string. |
| 695 | """ |
| 696 | if isinstance(string, str): |
| 697 | # This function is called a lot so for maximum performance, avoid |
| 698 | # involving regexps which would otherwise make the code much |
| 699 | # shorter. Regexps would need twice the time of this function. |
| 700 | if string: |
| 701 | if string == "0": |
| 702 | return True |
| 703 | if string[0] == "-": |
| 704 | string = string[1:] |
| 705 | if not string: |
| 706 | return False |
| 707 | if "1" <= string[0] <= "9": |
| 708 | return string.isdigit() |
| 709 | |
| 710 | return False |
| 711 | |
| 712 | |
| 713 | # This matches things like "<(asdf)", "<!(cmd)", "<!@(cmd)", "<|(list)", |