Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
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
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
34aa9455
Commit
34aa9455
authored
May 23, 2015
by
Paul Morie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use byte buffer in expansion/expand.go
parent
4292866c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
5 deletions
+9
-5
expand.go
third_party/golang/expansion/expand.go
+9
-5
No files found.
third_party/golang/expansion/expand.go
View file @
34aa9455
package
expansion
package
expansion
import
(
"bytes"
)
const
(
const
(
operator
=
'$'
operator
=
'$'
referenceOpener
=
'('
referenceOpener
=
'('
...
@@ -32,13 +36,13 @@ func MappingFuncFor(context ...map[string]string) func(string) string {
...
@@ -32,13 +36,13 @@ func MappingFuncFor(context ...map[string]string) func(string) string {
// the expansion spec using the given mapping function to resolve the
// the expansion spec using the given mapping function to resolve the
// values of variables.
// values of variables.
func
Expand
(
input
string
,
mapping
func
(
string
)
string
)
string
{
func
Expand
(
input
string
,
mapping
func
(
string
)
string
)
string
{
buf
:=
make
([]
byte
,
0
,
2
*
len
(
input
))
var
buf
bytes
.
Buffer
checkpoint
:=
0
checkpoint
:=
0
for
cursor
:=
0
;
cursor
<
len
(
input
);
cursor
++
{
for
cursor
:=
0
;
cursor
<
len
(
input
);
cursor
++
{
if
input
[
cursor
]
==
operator
&&
cursor
+
1
<
len
(
input
)
{
if
input
[
cursor
]
==
operator
&&
cursor
+
1
<
len
(
input
)
{
// Copy the portion of the input string since the last
// Copy the portion of the input string since the last
// checkpoint into the buffer
// checkpoint into the buffer
buf
=
append
(
buf
,
input
[
checkpoint
:
cursor
]
...
)
buf
.
WriteString
(
input
[
checkpoint
:
cursor
]
)
// Attempt to read the variable name as defined by the
// Attempt to read the variable name as defined by the
// syntax from the input string
// syntax from the input string
...
@@ -48,10 +52,10 @@ func Expand(input string, mapping func(string) string) string {
...
@@ -48,10 +52,10 @@ func Expand(input string, mapping func(string) string) string {
// We were able to read a variable name correctly;
// We were able to read a variable name correctly;
// apply the mapping to the variable name and copy the
// apply the mapping to the variable name and copy the
// bytes into the buffer
// bytes into the buffer
buf
=
append
(
buf
,
mapping
(
read
)
...
)
buf
.
WriteString
(
mapping
(
read
)
)
}
else
{
}
else
{
// Not a variable name; copy the read bytes into the buffer
// Not a variable name; copy the read bytes into the buffer
buf
=
append
(
buf
,
read
...
)
buf
.
WriteString
(
read
)
}
}
// Advance the cursor in the input string to account for
// Advance the cursor in the input string to account for
...
@@ -65,7 +69,7 @@ func Expand(input string, mapping func(string) string) string {
...
@@ -65,7 +69,7 @@ func Expand(input string, mapping func(string) string) string {
// Return the buffer and any remaining unwritten bytes in the
// Return the buffer and any remaining unwritten bytes in the
// input string.
// input string.
return
string
(
buf
)
+
input
[
checkpoint
:
]
return
buf
.
String
(
)
+
input
[
checkpoint
:
]
}
}
// tryReadVariableName attempts to read a variable name from the input
// tryReadVariableName attempts to read a variable name from the input
...
...
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