Giter VIP home page Giter VIP logo

Comments (4)

TwiN avatar TwiN commented on August 15, 2024

Have you tried using WithSanitizeSpaces(false)?

from go-away.

karthikrajanuber avatar karthikrajanuber commented on August 15, 2024

Hi @TwiN
Yes I tried using WithSanitizeSapces(false) -> it removes the spaces in the the string. But still it is not working.

Screenshot 2022-08-24 at 12 55 17 PM

Screenshot 2022-08-24 at 12 54 13 PM

I tried modifying the code but not able. The thing is instead of doing substring search, I need to search for exact word.

from go-away.

TwiN avatar TwiN commented on August 15, 2024

Ah you're right, yeah. We'd need to add a new WithExactWord(bool) feature

from go-away.

karthikrajanuber avatar karthikrajanuber commented on August 15, 2024

I got this with the below code

	for currentIndex != -1 {
		if currentIndex == 0 {
			searchWord = word + " "
			wordPlacement = 1
		}
		if len([]rune(" "+word))+strings.LastIndex(s, " "+word) == len([]rune(s)) {
			searchWord = " " + word
			wordPlacement = 2
		}
		str := strings.Split(s, " ")
		if len(str) == 1 {
			if foundIndex := strings.Index(s[currentIndex:], strings.TrimSpace(searchWord)); foundIndex != -1 {
				for i := 0; i < len([]rune(strings.TrimSpace(searchWord))); i++ {
					runeIndex := g.indexToRune(string(censored), currentIndex+foundIndex+i)
					censored[originalIndexes[runeIndex]] = '*'
				}
				currentIndex += foundIndex + len([]rune(strings.TrimSpace(searchWord)))
			} else {
				break
			}
		}

		if foundIndex := strings.Index(s[currentIndex:], searchWord); foundIndex != -1 {
			if wordPlacement == 0 {
				for i := 0; i < len([]rune(searchWord))-1; i++ {
					runeIndex := g.indexToRune(string(censored), currentIndex+foundIndex+i)
					censored[originalIndexes[runeIndex]] = '*'
				}
				currentIndex += foundIndex + len([]rune(searchWord))
			}
			if wordPlacement == 1 {
				for i := 0; i < len([]rune(strings.TrimSpace(searchWord))); i++ {
					runeIndex := g.indexToRune(string(censored), currentIndex+foundIndex+i)
					censored[originalIndexes[runeIndex]] = '*'
				}
				currentIndex += foundIndex + len([]rune(strings.TrimSpace(searchWord)))
			}
			if wordPlacement == 2 {
				for i := 1; i < len([]rune(strings.TrimSpace(searchWord)))+1; i++ {
					runeIndex := g.indexToRune(string(censored), currentIndex+foundIndex+i)
					censored[originalIndexes[runeIndex]] = '*'
				}
				currentIndex += foundIndex + len([]rune(strings.TrimSpace(searchWord)))
			}
			wordPlacement = 0
		} else {
			break
		}
	}

from go-away.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.