Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
02a0d651
Commit
02a0d651
authored
Jul 12, 2012
by
yorah
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add git_buf_unescape and git__unescape to unescape all characters in a string (in-place)
parent
944d250f
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
55 additions
and
11 deletions
+55
-11
src/attr_file.c
+1
-11
src/buffer.c
+4
-0
src/buffer.h
+3
-0
src/util.c
+18
-0
src/util.h
+9
-0
tests-clar/core/buffer.c
+20
-0
No files found.
src/attr_file.c
View file @
02a0d651
...
...
@@ -426,17 +426,7 @@ int git_attr_fnmatch__parse(
return
-
1
;
}
else
{
/* strip '\' that might have be used for internal whitespace */
char
*
to
=
spec
->
pattern
;
for
(
scan
=
spec
->
pattern
;
*
scan
;
to
++
,
scan
++
)
{
if
(
*
scan
==
'\\'
)
scan
++
;
/* skip '\' but include next char */
if
(
to
!=
scan
)
*
to
=
*
scan
;
}
if
(
to
!=
scan
)
{
*
to
=
'\0'
;
spec
->
length
=
(
to
-
spec
->
pattern
);
}
spec
->
length
=
git__unescape
(
spec
->
pattern
);
}
return
0
;
...
...
src/buffer.c
View file @
02a0d651
...
...
@@ -496,3 +496,7 @@ bool git_buf_is_binary(const git_buf *buf)
return
((
printable
>>
7
)
<
nonprintable
);
}
void
git_buf_unescape
(
git_buf
*
buf
)
{
buf
->
size
=
git__unescape
(
buf
->
ptr
);
}
src/buffer.h
View file @
02a0d651
...
...
@@ -151,4 +151,7 @@ int git_buf_common_prefix(git_buf *buf, const git_strarray *strings);
/* Check if buffer looks like it contains binary data */
bool
git_buf_is_binary
(
const
git_buf
*
buf
);
/* Unescape all characters in a buffer */
void
git_buf_unescape
(
git_buf
*
buf
);
#endif
src/util.c
View file @
02a0d651
...
...
@@ -435,3 +435,21 @@ int git__parse_bool(int *out, const char *value)
return
-
1
;
}
size_t
git__unescape
(
char
*
str
)
{
char
*
scan
,
*
pos
=
str
;
for
(
scan
=
str
;
*
scan
;
pos
++
,
scan
++
)
{
if
(
*
scan
==
'\\'
&&
*
(
scan
+
1
)
!=
'\0'
)
scan
++
;
/* skip '\' but include next char */
if
(
pos
!=
scan
)
*
pos
=
*
scan
;
}
if
(
pos
!=
scan
)
{
*
pos
=
'\0'
;
}
return
(
pos
-
str
);
}
src/util.h
View file @
02a0d651
...
...
@@ -238,4 +238,13 @@ extern int git__parse_bool(int *out, const char *value);
*/
int
git__date_parse
(
git_time_t
*
out
,
const
char
*
date
);
/*
* Unescapes a string in-place.
*
* Edge cases behavior:
* - "jackie\" -> "jacky\"
* - "chan\\" -> "chan\"
*/
extern
size_t
git__unescape
(
char
*
str
);
#endif
/* INCLUDE_util_h__ */
tests-clar/core/buffer.c
View file @
02a0d651
...
...
@@ -658,3 +658,23 @@ void test_core_buffer__puts_escaped(void)
git_buf_free
(
&
a
);
}
static
void
assert_unescape
(
char
*
expected
,
char
*
to_unescape
)
{
git_buf
buf
=
GIT_BUF_INIT
;
cl_git_pass
(
git_buf_sets
(
&
buf
,
to_unescape
));
git_buf_unescape
(
&
buf
);
cl_assert_equal_s
(
expected
,
buf
.
ptr
);
cl_assert_equal_i
(
strlen
(
expected
),
buf
.
size
);
git_buf_free
(
&
buf
);
}
void
test_core_buffer__unescape
(
void
)
{
assert_unescape
(
"Escaped
\\
"
,
"Es
\\
ca
\\
ped
\\
"
);
assert_unescape
(
"Es
\\
caped
\\
"
,
"Es
\\\\
ca
\\
ped
\\\\
"
);
assert_unescape
(
"
\\
"
,
"
\\
"
);
assert_unescape
(
"
\\
"
,
"
\\\\
"
);
assert_unescape
(
""
,
""
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment