Sha256: 532919299c309ec48bf1d96d2f2f9ab220c86c4e92d409849967cbf741b2bbbe

Contents?: true

Size: 668 Bytes

Versions: 396

Compression:

Stored size: 668 Bytes

Contents

package counter

import "unicode"

// Incorrect implementation: assumes ASCII.
type Impl3 struct {
	newlines, characters, letters int
	lastChar                      rune
}

func (c *Impl3) AddString(s string) {
	for i := 0; i < len(s); i++ {
		char := rune(s[i])
		c.lastChar = char
		if char == '\n' {
			c.newlines++
		} else if unicode.IsLetter(char) {
			c.letters++
		}
		c.characters++
	}
}

func (c Impl3) Lines() int {
	switch {
	case c.characters == 0:
		return 0
	case c.lastChar == '\n':
		return c.newlines
	default:
		return c.newlines + 1
	}
}

func (c Impl3) Letters() int    { return c.letters }
func (c Impl3) Characters() int { return c.characters }

Version data entries

396 entries across 396 versions & 1 rubygems

Version Path
trackler-2.2.1.78 tracks/go/exercises/counter/impl3.go
trackler-2.2.1.77 tracks/go/exercises/counter/impl3.go
trackler-2.2.1.76 tracks/go/exercises/counter/impl3.go
trackler-2.2.1.75 tracks/go/exercises/counter/impl3.go
trackler-2.2.1.74 tracks/go/exercises/counter/impl3.go
trackler-2.2.1.73 tracks/go/exercises/counter/impl3.go
trackler-2.2.1.72 tracks/go/exercises/counter/impl3.go
trackler-2.2.1.71 tracks/go/exercises/counter/impl3.go
trackler-2.2.1.70 tracks/go/exercises/counter/impl3.go
trackler-2.2.1.69 tracks/go/exercises/counter/impl3.go
trackler-2.2.1.68 tracks/go/exercises/counter/impl3.go
trackler-2.2.1.67 tracks/go/exercises/counter/impl3.go
trackler-2.2.1.66 tracks/go/exercises/counter/impl3.go
trackler-2.2.1.65 tracks/go/exercises/counter/impl3.go
trackler-2.2.1.64 tracks/go/exercises/counter/impl3.go
trackler-2.2.1.63 tracks/go/exercises/counter/impl3.go
trackler-2.2.1.62 tracks/go/exercises/counter/impl3.go
trackler-2.2.1.61 tracks/go/exercises/counter/impl3.go
trackler-2.2.1.60 tracks/go/exercises/counter/impl3.go
trackler-2.2.1.59 tracks/go/exercises/counter/impl3.go