Home / Function/ removeRepeatedChar() — gin Function Reference

removeRepeatedChar() — gin Function Reference

Architecture documentation for the removeRepeatedChar() function in path.go from the gin codebase.

Entity Profile

Dependency Diagram

graph TD
  1e0289fd_288d_87a1_00a7_d49ab776a179["removeRepeatedChar()"]
  2cd24ad1_a2fb_ea62_1740_f464205e2482["path.go"]
  1e0289fd_288d_87a1_00a7_d49ab776a179 -->|defined in| 2cd24ad1_a2fb_ea62_1740_f464205e2482
  c9e13c4f_e8ac_23df_c197_fd4f4a014ce5["bufApp()"]
  1e0289fd_288d_87a1_00a7_d49ab776a179 -->|calls| c9e13c4f_e8ac_23df_c197_fd4f4a014ce5
  style 1e0289fd_288d_87a1_00a7_d49ab776a179 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

Defined In

Calls

Frequently Asked Questions

What does removeRepeatedChar() do?
removeRepeatedChar() is a function in the gin codebase, defined in path.go.
Where is removeRepeatedChar() defined?
removeRepeatedChar() is defined in path.go at line 155.
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