-
-
Save mmcdole/e82cf881e5a6e1f0c894 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bufio" | |
"fmt" | |
"os" | |
"regexp" | |
) | |
var ( | |
literalSlash = regexp.MustCompile(`\\\\`) | |
escapedQuote = regexp.MustCompile(`\\"`) | |
hexLetter = regexp.MustCompile(`\\x[a-f0-9]{2}`) | |
) | |
func main() { | |
scanner := bufio.NewScanner(os.Stdin) | |
codeChars := 0 | |
valueChars := 0 | |
for scanner.Scan() { | |
line := scanner.Text() | |
codeChars += len(line) | |
// Surrounding Quotes | |
line = line[1 : len(line)-1] | |
// Slash Literals | |
line = literalSlash.ReplaceAllString(line, "\\") | |
// Escaped Quotes | |
line = escapedQuote.ReplaceAllString(line, "\"") | |
// Hex Letter | |
line = hexLetter.ReplaceAllString(line, "!") | |
valueChars += len(line) | |
} | |
fmt.Printf("codeChars: %d - valueChars: %d = %d\n", codeChars, valueChars, codeChars-valueChars) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment