Repository navigation
Expand file tree
/
Copy pathutil.go
More file actions
117 lines (102 loc) · 2.28 KB
/
Copy pathutil.go
File metadata and controls
117 lines (102 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package main
import (
"log"
"os"
"path/filepath"
"strings"
"time"
)
// RoutineDelimeter : mysql procedure delemiter
const RoutineDelimeter = "//"
func mysqlEscape(source []byte) string {
if len(source) == 0 {
return ""
}
dest := make([]byte, 0, 2*len(source))
var escape byte
for i := 0; i < len(source); i++ {
c := source[i]
escape = 0
switch c {
case 0: /* Must be escaped for 'mysql' */
escape = '0'
case '\n': /* Must be escaped for logs */
escape = 'n'
case '\r':
escape = 'r'
case '\\':
escape = '\\'
case '\'':
escape = '\''
case '"': /* Better safe than sorry */
escape = '"'
case '\032': /* This gives problems on Win32 */
escape = 'Z'
}
if escape != 0 {
dest = append(dest, '\\', escape)
} else {
dest = append(dest, c)
}
}
return string(dest)
}
//CheckFilePath : Check ouptput file path.
func CheckFilePath(name string) string {
name = strings.Replace(name, "[DATE]", time.Now().Format("20060102"), -1)
name = strings.Replace(name, "[DATETIME]", time.Now().Format("20060102150405"), -1)
dir := filepath.Dir(name)
if _, err := os.Stat(dir); os.IsNotExist(err) {
if err := os.MkdirAll(dir, 0755); err != nil {
log.Fatalln("mkdir err", dir, err)
return ""
}
}
return name
}
/*
\ (역방향 슬래시) ... 따라서 역방향 슬래시를 그대로 표현하려면 역방향 슬래시 기호를 두 번 쓰면 됩니다. \\ 이렇게요.
` (backtick = 제2강세 악센트 기호)
* 별표
_ 언더바
{ } 중괄호
[ ] 대괄호
( ) 소괄호
# 우물정자
+ 플러스기호
- 마이너스 기호
. 마침표
! 느낌표
*/
var r = strings.NewReplacer(
"\\", "\\\\",
"`", "\\`",
"*", "\\*",
"_", "\\_",
"{", "\\{",
"{", "\\}",
"[", "\\[",
"]", "\\]",
"(", "\\(",
")", "\\)",
"#", "\\#",
"+", "\\+",
"-", "\\-",
".", "\\.",
"!", "\\!")
// MDReplace replace md special char
func MDReplace(src string) string {
ret := strings.ToLower(src)
ret = strings.Replace(ret, " ", "", -1)
ret = strings.Replace(ret, "_", "", -1)
return ret
}
// WikiReplace replace wiki special char
func WikiReplace(src string) string {
//return r.Replace(src)
return strings.Replace(src, " ", "", -1)
}
// CommentReplace mysql comment replace
func CommentReplace(src string) string {
return strings.Replace(src, "'", "\\'", -1)
}