Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ByteCount([]byte, byte) int, Count(string, string) int #23

Closed
gonyyi opened this issue Jan 7, 2022 · 2 comments
Closed

Add ByteCount([]byte, byte) int, Count(string, string) int #23

gonyyi opened this issue Jan 7, 2022 · 2 comments
Labels
Accepted This will be fixed or enhanced for upcoming release Coded Feature/fix is ready to be added to the code Feature - New New feature or request

Comments

@gonyyi
Copy link
Owner

gonyyi commented Jan 7, 2022

This will be used to check if number of delimiter is correct

// Count counts string lookup value from string s, returns total
func Count(s string, lookup string) int {
	count := 0
	for i:=0; i<len(s)-len(lookup)+1; i++ {
		if s[i:i+len(lookup)] == lookup {
			count += 1
		}
	}
	return count
}

// ByteCount counts byte `c` value from bytes `p`, returns total
func ByteCount(p []byte, c byte) int {
	count := 0
	for _, v := range p {
		if v == c {
			count += 1
		}
	}
	return count
}
@gonyyi gonyyi added Feature - New New feature or request Accepted This will be fixed or enhanced for upcoming release labels Jan 7, 2022
@gonyyi
Copy link
Owner Author

gonyyi commented Jan 7, 2022

Change: for ByteCount, only count single byte

@gonyyi gonyyi added the Coded Feature/fix is ready to be added to the code label Jan 7, 2022
gonyyi added a commit that referenced this issue Jan 11, 2022
@gonyyi
Copy link
Owner Author

gonyyi commented Jan 11, 2022

Added 5904be4

@gonyyi gonyyi closed this as completed Jan 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Accepted This will be fixed or enhanced for upcoming release Coded Feature/fix is ready to be added to the code Feature - New New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant