mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-25 16:55:11 +01:00
Have dumbindent no longer treat labels specially
This commit is contained in:
1 parent
6424bae087
commit
0ad5f9b617
2 files changed
+1
-26
No files matched your search
@@ -138,9 +138,6 @@ func FormatBytes(dst []byte, src []byte) []byte {
|
|||||||
if (nParens > 0) || hanging {
|
if (nParens > 0) || hanging {
|
||||||
indent += 4
|
indent += 4
|
||||||
}
|
}
|
||||||
if (indent >= 2) && isLabel(line) {
|
|
||||||
indent -= 2
|
|
||||||
}
|
|
||||||
for indent > 0 {
|
for indent > 0 {
|
||||||
n := indent
|
n := indent
|
||||||
if n > len(spaces) {
|
if n > len(spaces) {
|
||||||
@@ -234,28 +231,6 @@ func trimTrailingWhiteSpace(s []byte) []byte {
|
|||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
// isLabel returns whether s looks like "foo:" or "bar_baz:;".
|
|
||||||
func isLabel(s []byte) bool {
|
|
||||||
for (len(s) > 0) && (s[len(s)-1] == ';') {
|
|
||||||
s = s[:len(s)-1]
|
|
||||||
}
|
|
||||||
if (len(s) < 2) || (s[len(s)-1] != ':') {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
s = s[:len(s)-1]
|
|
||||||
for _, c := range s {
|
|
||||||
switch {
|
|
||||||
case ('0' <= c) && (c <= '9'):
|
|
||||||
case ('A' <= c) && (c <= 'Z'):
|
|
||||||
case ('a' <= c) && (c <= 'z'):
|
|
||||||
case c == '_':
|
|
||||||
default:
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
// lastNonWhiteSpace returns the 'z' in "abc xyz ". It returns '\x00' if s
|
// lastNonWhiteSpace returns the 'z' in "abc xyz ". It returns '\x00' if s
|
||||||
// consists entirely of spaces or tabs.
|
// consists entirely of spaces or tabs.
|
||||||
func lastNonWhiteSpace(s []byte) byte {
|
func lastNonWhiteSpace(s []byte) byte {
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ func TestFormatBytes(tt *testing.T) {
|
|||||||
src: " a['key'] = /*{\n\n\nX*/ ; \nb = {\nc = 0\n",
|
src: " a['key'] = /*{\n\n\nX*/ ; \nb = {\nc = 0\n",
|
||||||
want: "a['key'] = /*{\n\n\nX*/ ;\nb = {\n c = 0\n",
|
want: "a['key'] = /*{\n\n\nX*/ ;\nb = {\n c = 0\n",
|
||||||
}, {
|
}, {
|
||||||
// Label.
|
// Nested blocks with label.
|
||||||
src: "if (b) {\nlabel:\nswitch (i) {\ncase 0:\nj = k\nbreak;\n}\n}\n",
|
src: "if (b) {\nlabel:\nswitch (i) {\ncase 0:\nj = k\nbreak;\n}\n}\n",
|
||||||
want: "if (b) {\n label:\n switch (i) {\n case 0:\n j = k\n break;\n }\n}\n",
|
want: "if (b) {\n label:\n switch (i) {\n case 0:\n j = k\n break;\n }\n}\n",
|
||||||
}}
|
}}
|
||||||
|
|||||||
Reference in new issue
Block a user