removeRepeatedChar() — gin Function Reference
Architecture documentation for the removeRepeatedChar() function in path.go from the gin codebase.
Entity Profile
Dependency Diagram
graph TD a665bfd6_6cb2_f9b7_dba0_b277247d1360["removeRepeatedChar()"] 900407ca_06e1_6993_0fcb_3023e51081c8["bufApp()"] a665bfd6_6cb2_f9b7_dba0_b277247d1360 -->|calls| 900407ca_06e1_6993_0fcb_3023e51081c8 style a665bfd6_6cb2_f9b7_dba0_b277247d1360 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
path.go lines 155–203
func removeRepeatedChar(s string, char byte) string {
// Check if there are any consecutive chars
hasRepeatedChar := false
for i := 1; i < len(s); i++ {
if s[i] == char && s[i-1] == char {
hasRepeatedChar = true
break
}
}
if !hasRepeatedChar {
return s
}
// Reasonably sized buffer on stack to avoid allocations in the common case.
buf := make([]byte, 0, stackBufSize)
// Invariants:
// reading from s; r is index of next byte to process.
// writing to buf; w is index of next byte to write.
r := 0
w := 0
for n := len(s); r < n; {
if s[r] == char {
// Write the first char
bufApp(&buf, s, w, char)
w++
r++
// Skip all consecutive chars
for r < n && s[r] == char {
r++
}
} else {
// Copy non-char character
bufApp(&buf, s, w, s[r])
w++
r++
}
}
// If the original string was not modified (or only shortened at the end),
// return the respective substring of the original string.
// Otherwise, return a new string from the buffer.
if len(buf) == 0 {
return s[:w]
}
return string(buf[:w])
}
Domain
Subdomains
Calls
Source
Frequently Asked Questions
What does removeRepeatedChar() do?
removeRepeatedChar() is a function in the gin codebase.
What does removeRepeatedChar() call?
removeRepeatedChar() calls 1 function(s): bufApp.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free