]> git.lizzy.rs Git - micro.git/commitdiff
Use CharacterCount over RuneCount
authorZachary Yedidia <zyedidia@gmail.com>
Wed, 20 May 2020 20:47:08 +0000 (16:47 -0400)
committerZachary Yedidia <zyedidia@gmail.com>
Wed, 20 May 2020 20:47:08 +0000 (16:47 -0400)
17 files changed:
internal/action/actions.go
internal/action/bufpane.go
internal/action/command.go
internal/buffer/autocomplete.go
internal/buffer/buffer.go
internal/buffer/buffer_test.go
internal/buffer/cursor.go
internal/buffer/eventhandler.go
internal/buffer/line_array.go
internal/buffer/loc.go
internal/buffer/save.go
internal/buffer/search.go
internal/display/infowindow.go
internal/display/statusline.go
internal/display/tabwindow.go
internal/display/termwindow.go
internal/util/unicode.go

index c42b6c8a6d2f16522e2ace4d9c2d1544f39c9761..ae19a3f917dfe2d7b30432d9a70a91c9ceec7be8 100644 (file)
@@ -5,7 +5,6 @@ import (
        "runtime"
        "strings"
        "time"
-       "unicode/utf8"
 
        shellquote "github.com/kballard/go-shellquote"
        "github.com/zyedidia/clipboard"
@@ -175,7 +174,7 @@ func (h *BufPane) CursorRight() bool {
                if tabstospaces && tabmovement {
                        tabsize := int(h.Buf.Settings["tabsize"].(float64))
                        line := h.Buf.LineBytes(h.Cursor.Y)
-                       if h.Cursor.X+tabsize < utf8.RuneCount(line) && util.IsSpaces(line[h.Cursor.X:h.Cursor.X+tabsize]) && util.IsBytesWhitespace(line[0:h.Cursor.X]) {
+                       if h.Cursor.X+tabsize < util.CharacterCount(line) && util.IsSpaces(line[h.Cursor.X:h.Cursor.X+tabsize]) && util.IsBytesWhitespace(line[0:h.Cursor.X]) {
                                for i := 0; i < tabsize; i++ {
                                        h.Cursor.Right()
                                }
@@ -486,7 +485,7 @@ func (h *BufPane) InsertNewline() bool {
                // Remove the whitespaces if keepautoindent setting is off
                if util.IsSpacesOrTabs(h.Buf.LineBytes(h.Cursor.Y-1)) && !h.Buf.Settings["keepautoindent"].(bool) {
                        line := h.Buf.LineBytes(h.Cursor.Y - 1)
-                       h.Buf.Remove(buffer.Loc{X: 0, Y: h.Cursor.Y - 1}, buffer.Loc{X: utf8.RuneCount(line), Y: h.Cursor.Y - 1})
+                       h.Buf.Remove(buffer.Loc{X: 0, Y: h.Cursor.Y - 1}, buffer.Loc{X: util.CharacterCount(line), Y: h.Cursor.Y - 1})
                }
        }
        h.Cursor.LastVisualX = h.Cursor.GetVisualX()
@@ -511,7 +510,7 @@ func (h *BufPane) Backspace() bool {
                // tab (tabSize number of spaces)
                lineStart := util.SliceStart(h.Buf.LineBytes(h.Cursor.Y), h.Cursor.X)
                tabSize := int(h.Buf.Settings["tabsize"].(float64))
-               if h.Buf.Settings["tabstospaces"].(bool) && util.IsSpaces(lineStart) && len(lineStart) != 0 && utf8.RuneCount(lineStart)%tabSize == 0 {
+               if h.Buf.Settings["tabstospaces"].(bool) && util.IsSpaces(lineStart) && len(lineStart) != 0 && util.CharacterCount(lineStart)%tabSize == 0 {
                        loc := h.Cursor.Loc
                        h.Buf.Remove(loc.Move(-tabSize, h.Buf), loc)
                } else {
index 24086d745778d6d7e10d4522e4f714ee442c7466..51d4ebd1fd19ff9a671cb413d8370a3b420a0e58 100644 (file)
@@ -190,7 +190,7 @@ type BufPane struct {
        tripleClick bool
 
        // Last search stores the last successful search for FindNext and FindPrev
-       lastSearch string
+       lastSearch      string
        lastSearchRegex bool
        // Should the current multiple cursor selection search based on word or
        // based on selection (false for selection, true for word)
index 8361e5a10c9252e293e26fc203b9eaea3a85f2b7..cae2b3f6d9cda6ebff23cb2a8e34b9bce9cd7c49 100644 (file)
@@ -10,7 +10,6 @@ import (
        "regexp"
        "strconv"
        "strings"
-       "unicode/utf8"
 
        shellquote "github.com/kballard/go-shellquote"
        "github.com/zyedidia/micro/v2/internal/buffer"
@@ -703,7 +702,7 @@ func (h *BufPane) GotoCmd(args []string) {
                                return
                        }
                        line = util.Clamp(line-1, 0, h.Buf.LinesNum()-1)
-                       col = util.Clamp(col-1, 0, utf8.RuneCount(h.Buf.LineBytes(line)))
+                       col = util.Clamp(col-1, 0, util.CharacterCount(h.Buf.LineBytes(line)))
                        h.Cursor.GotoLoc(buffer.Loc{col, line})
                } else {
                        line, err := strconv.Atoi(args[0])
@@ -827,7 +826,7 @@ func (h *BufPane) ReplaceCmd(args []string) {
                                        nreplaced++
                                } else if !canceled && !yes {
                                        searchLoc = locs[0]
-                                       searchLoc.X += utf8.RuneCount(replace)
+                                       searchLoc.X += util.CharacterCount(replace)
                                } else if canceled {
                                        h.Cursor.ResetSelection()
                                        h.Buf.RelocateCursors()
index 3bb4d3074b62ee218fd59aaff05ffc7110a4a0a3..7af3f0b7f4429c574a8cf6d27e8e2b22035a04aa 100644 (file)
@@ -6,7 +6,6 @@ import (
        "os"
        "sort"
        "strings"
-       "unicode/utf8"
 
        "github.com/zyedidia/micro/v2/internal/util"
 )
@@ -54,7 +53,7 @@ func (b *Buffer) CycleAutocomplete(forward bool) {
        start := c.Loc
        end := c.Loc
        if prevSuggestion < len(b.Suggestions) && prevSuggestion >= 0 {
-               start = end.Move(-utf8.RuneCountInString(b.Completions[prevSuggestion]), b)
+               start = end.Move(-util.CharacterCountInString(b.Completions[prevSuggestion]), b)
        } else {
                // end = start.Move(1, b)
        }
@@ -82,7 +81,7 @@ func GetWord(b *Buffer) ([]byte, int) {
 
        args := bytes.FieldsFunc(l, util.IsNonAlphaNumeric)
        input := args[len(args)-1]
-       return input, c.X - utf8.RuneCount(input)
+       return input, c.X - util.CharacterCount(input)
 }
 
 // GetArg gets the most recent word (separated by ' ' only)
@@ -98,7 +97,7 @@ func GetArg(b *Buffer) (string, int) {
                if i == len(args)-1 {
                        break
                }
-               argstart += utf8.RuneCount(a) + 1
+               argstart += util.CharacterCount(a) + 1
        }
 
        return input, argstart
@@ -162,7 +161,7 @@ func BufferComplete(b *Buffer) ([]string, []string) {
                return []string{}, []string{}
        }
 
-       inputLen := utf8.RuneCount(input)
+       inputLen := util.CharacterCount(input)
 
        suggestionsSet := make(map[string]struct{})
 
@@ -171,7 +170,7 @@ func BufferComplete(b *Buffer) ([]string, []string) {
                l := b.LineBytes(i)
                words := bytes.FieldsFunc(l, util.IsNonAlphaNumeric)
                for _, w := range words {
-                       if bytes.HasPrefix(w, input) && utf8.RuneCount(w) > inputLen {
+                       if bytes.HasPrefix(w, input) && util.CharacterCount(w) > inputLen {
                                strw := string(w)
                                if _, ok := suggestionsSet[strw]; !ok {
                                        suggestionsSet[strw] = struct{}{}
@@ -184,7 +183,7 @@ func BufferComplete(b *Buffer) ([]string, []string) {
                l := b.LineBytes(i)
                words := bytes.FieldsFunc(l, util.IsNonAlphaNumeric)
                for _, w := range words {
-                       if bytes.HasPrefix(w, input) && utf8.RuneCount(w) > inputLen {
+                       if bytes.HasPrefix(w, input) && util.CharacterCount(w) > inputLen {
                                strw := string(w)
                                if _, ok := suggestionsSet[strw]; !ok {
                                        suggestionsSet[strw] = struct{}{}
index ab9ada0671b8ea6e367e425f5d4e4efe6b1cba72..ebfdeabeafd221c34966dddb09c0436010a0f983 100644 (file)
@@ -15,7 +15,6 @@ import (
        "strings"
        "sync"
        "time"
-       "unicode/utf8"
 
        luar "layeh.com/gopher-luar"
 
@@ -809,7 +808,7 @@ func (b *Buffer) MoveLinesUp(start int, end int) {
        if end == len(b.lines) {
                b.Insert(
                        Loc{
-                               utf8.RuneCount(b.lines[end-1].data),
+                               util.CharacterCount(b.lines[end-1].data),
                                end - 1,
                        },
                        "\n"+l,
index f6ee3dee9af05f57b5c6688257db205df241cc89..305d1627487863a5689f4f26cf5f1c5d90e76259 100644 (file)
@@ -4,12 +4,12 @@ import (
        "math/rand"
        "strings"
        "testing"
-       "unicode/utf8"
 
        "github.com/stretchr/testify/assert"
        lua "github.com/yuin/gopher-lua"
-       ulua "github.com/zyedidia/micro/v2/internal/lua"
        "github.com/zyedidia/micro/v2/internal/config"
+       ulua "github.com/zyedidia/micro/v2/internal/lua"
+       "github.com/zyedidia/micro/v2/internal/util"
 )
 
 type operation struct {
@@ -158,9 +158,9 @@ func benchEdit(testingB *testing.B, nLines, nCursors int) {
        operations := make([]operation, nCursors)
        for i := range operations {
                startLine := (i * regionSize) + rand.Intn(regionSize-5)
-               startColumn := rand.Intn(utf8.RuneCountInString(b.Line(startLine)) + 1)
+               startColumn := rand.Intn(util.CharacterCountInString(b.Line(startLine)) + 1)
                endLine := startLine + 1 + rand.Intn(5)
-               endColumn := rand.Intn(utf8.RuneCountInString(b.Line(endLine)) + 1)
+               endColumn := rand.Intn(util.CharacterCountInString(b.Line(endLine)) + 1)
 
                operations[i] = operation{
                        start: Loc{startColumn, startLine},
index 4bd94808080aac8919974840fad597b68659f400..2d4d2da2c121eff564afe1b5d9a98d35807541fa 100644 (file)
@@ -1,15 +1,13 @@
 package buffer
 
 import (
-       "unicode/utf8"
-
        "github.com/zyedidia/clipboard"
        "github.com/zyedidia/micro/v2/internal/util"
 )
 
 // InBounds returns whether the given location is a valid character position in the given buffer
 func InBounds(pos Loc, buf *Buffer) bool {
-       if pos.Y < 0 || pos.Y >= len(buf.lines) || pos.X < 0 || pos.X > utf8.RuneCount(buf.LineBytes(pos.Y)) {
+       if pos.Y < 0 || pos.Y >= len(buf.lines) || pos.X < 0 || pos.X > util.CharacterCount(buf.LineBytes(pos.Y)) {
                return false
        }
 
@@ -76,8 +74,8 @@ func (c *Cursor) GetVisualX() int {
 
        bytes := c.buf.LineBytes(c.Y)
        tabsize := int(c.buf.Settings["tabsize"].(float64))
-       if c.X > utf8.RuneCount(bytes) {
-               c.X = utf8.RuneCount(bytes) - 1
+       if c.X > util.CharacterCount(bytes) {
+               c.X = util.CharacterCount(bytes) - 1
        }
 
        return util.StringWidth(bytes, c.X, tabsize)
@@ -102,7 +100,7 @@ func (c *Cursor) Start() {
 func (c *Cursor) StartOfText() {
        c.Start()
        for util.IsWhitespace(c.RuneUnder(c.X)) {
-               if c.X == utf8.RuneCount(c.buf.LineBytes(c.Y)) {
+               if c.X == util.CharacterCount(c.buf.LineBytes(c.Y)) {
                        break
                }
                c.Right()
@@ -114,7 +112,7 @@ func (c *Cursor) StartOfText() {
 func (c *Cursor) IsStartOfText() bool {
        x := 0
        for util.IsWhitespace(c.RuneUnder(x)) {
-               if x == utf8.RuneCount(c.buf.LineBytes(c.Y)) {
+               if x == util.CharacterCount(c.buf.LineBytes(c.Y)) {
                        break
                }
                x++
@@ -124,7 +122,7 @@ func (c *Cursor) IsStartOfText() bool {
 
 // End moves the cursor to the end of the line it is on
 func (c *Cursor) End() {
-       c.X = utf8.RuneCount(c.buf.LineBytes(c.Y))
+       c.X = util.CharacterCount(c.buf.LineBytes(c.Y))
        c.LastVisualX = c.GetVisualX()
 }
 
@@ -242,8 +240,8 @@ func (c *Cursor) UpN(amount int) {
        bytes := c.buf.LineBytes(proposedY)
        c.X = c.GetCharPosInLine(bytes, c.LastVisualX)
 
-       if c.X > utf8.RuneCount(bytes) || (amount < 0 && proposedY == c.Y) {
-               c.X = utf8.RuneCount(bytes)
+       if c.X > util.CharacterCount(bytes) || (amount < 0 && proposedY == c.Y) {
+               c.X = util.CharacterCount(bytes)
        }
 
        c.Y = proposedY
@@ -285,7 +283,7 @@ func (c *Cursor) Right() {
        if c.Loc == c.buf.End() {
                return
        }
-       if c.X < utf8.RuneCount(c.buf.LineBytes(c.Y)) {
+       if c.X < util.CharacterCount(c.buf.LineBytes(c.Y)) {
                c.X++
        } else {
                c.Down()
@@ -306,8 +304,8 @@ func (c *Cursor) Relocate() {
 
        if c.X < 0 {
                c.X = 0
-       } else if c.X > utf8.RuneCount(c.buf.LineBytes(c.Y)) {
-               c.X = utf8.RuneCount(c.buf.LineBytes(c.Y))
+       } else if c.X > util.CharacterCount(c.buf.LineBytes(c.Y)) {
+               c.X = util.CharacterCount(c.buf.LineBytes(c.Y))
        }
 }
 
@@ -333,7 +331,7 @@ func (c *Cursor) SelectWord() {
        c.SetSelectionStart(Loc{backward, c.Y})
        c.OrigSelection[0] = c.CurSelection[0]
 
-       lineLen := utf8.RuneCount(c.buf.LineBytes(c.Y)) - 1
+       lineLen := util.CharacterCount(c.buf.LineBytes(c.Y)) - 1
        for forward < lineLen && util.IsWordChar(c.RuneUnder(forward+1)) {
                forward++
        }
@@ -365,7 +363,7 @@ func (c *Cursor) AddWordToSelection() {
        if c.Loc.GreaterThan(c.OrigSelection[1]) {
                forward := c.X
 
-               lineLen := utf8.RuneCount(c.buf.LineBytes(c.Y)) - 1
+               lineLen := util.CharacterCount(c.buf.LineBytes(c.Y)) - 1
                for forward < lineLen && util.IsWordChar(c.RuneUnder(forward+1)) {
                        forward++
                }
@@ -392,7 +390,7 @@ func (c *Cursor) SelectTo(loc Loc) {
 // WordRight moves the cursor one word to the right
 func (c *Cursor) WordRight() {
        for util.IsWhitespace(c.RuneUnder(c.X)) {
-               if c.X == utf8.RuneCount(c.buf.LineBytes(c.Y)) {
+               if c.X == util.CharacterCount(c.buf.LineBytes(c.Y)) {
                        c.Right()
                        return
                }
@@ -400,7 +398,7 @@ func (c *Cursor) WordRight() {
        }
        c.Right()
        for util.IsWordChar(c.RuneUnder(c.X)) {
-               if c.X == utf8.RuneCount(c.buf.LineBytes(c.Y)) {
+               if c.X == util.CharacterCount(c.buf.LineBytes(c.Y)) {
                        return
                }
                c.Right()
@@ -429,7 +427,7 @@ func (c *Cursor) WordLeft() {
 // RuneUnder returns the rune under the given x position
 func (c *Cursor) RuneUnder(x int) rune {
        line := c.buf.LineBytes(c.Y)
-       if len(line) == 0 || x >= utf8.RuneCount(line) {
+       if len(line) == 0 || x >= util.CharacterCount(line) {
                return '\n'
        } else if x < 0 {
                x = 0
index 4ce302418c0995b9ffa39763038a49811110c94f..3862d696029394e408ad1dd57c0e80ff8e0a1cd0 100644 (file)
@@ -3,12 +3,12 @@ package buffer
 import (
        "bytes"
        "time"
-       "unicode/utf8"
 
        dmp "github.com/sergi/go-diff/diffmatchpatch"
        "github.com/zyedidia/micro/v2/internal/config"
        ulua "github.com/zyedidia/micro/v2/internal/lua"
        "github.com/zyedidia/micro/v2/internal/screen"
+       "github.com/zyedidia/micro/v2/internal/util"
        luar "layeh.com/gopher-luar"
 )
 
@@ -62,10 +62,10 @@ func (eh *EventHandler) DoTextEvent(t *TextEvent, useUndo bool) {
        var textX int
        if t.EventType == TextEventInsert {
                linecount := eh.buf.LinesNum() - oldl
-               textcount := utf8.RuneCount(text)
+               textcount := util.CharacterCount(text)
                lastnl = bytes.LastIndex(text, []byte{'\n'})
                if lastnl >= 0 {
-                       endX = utf8.RuneCount(text[lastnl+1:])
+                       endX = util.CharacterCount(text[lastnl+1:])
                        textX = endX
                } else {
                        endX = start.X + textcount
@@ -123,7 +123,7 @@ func ExecuteTextEvent(t *TextEvent, buf *SharedBuffer) {
                        t.Deltas[i].Text = buf.remove(d.Start, d.End)
                        buf.insert(d.Start, d.Text)
                        t.Deltas[i].Start = d.Start
-                       t.Deltas[i].End = Loc{d.Start.X + utf8.RuneCount(d.Text), d.Start.Y}
+                       t.Deltas[i].End = Loc{d.Start.X + util.CharacterCount(d.Text), d.Start.Y}
                }
                for i, j := 0, len(t.Deltas)-1; i < j; i, j = i+1, j-1 {
                        t.Deltas[i], t.Deltas[j] = t.Deltas[j], t.Deltas[i]
@@ -166,12 +166,12 @@ func (eh *EventHandler) ApplyDiff(new string) {
        loc := eh.buf.Start()
        for _, d := range diff {
                if d.Type == dmp.DiffDelete {
-                       eh.Remove(loc, loc.MoveLA(utf8.RuneCountInString(d.Text), eh.buf.LineArray))
+                       eh.Remove(loc, loc.MoveLA(util.CharacterCountInString(d.Text), eh.buf.LineArray))
                } else {
                        if d.Type == dmp.DiffInsert {
                                eh.Insert(loc, d.Text)
                        }
-                       loc = loc.MoveLA(utf8.RuneCountInString(d.Text), eh.buf.LineArray)
+                       loc = loc.MoveLA(util.CharacterCountInString(d.Text), eh.buf.LineArray)
                }
        }
 }
index c47a3948821f8e801719425057d29e247d816325..325e2f52bb31c3f79477e4e45b60205ec73cbdd4 100644 (file)
@@ -5,10 +5,9 @@ import (
        "bytes"
        "io"
        "sync"
-       "unicode/utf8"
 
-       "github.com/zyedidia/micro/v2/pkg/highlight"
        "github.com/zyedidia/micro/v2/internal/util"
+       "github.com/zyedidia/micro/v2/pkg/highlight"
 )
 
 // Finds the byte index of the nth rune in a byte slice
@@ -300,7 +299,7 @@ func (la *LineArray) Start() Loc {
 // End returns the location of the last character in the buffer
 func (la *LineArray) End() Loc {
        numlines := len(la.lines)
-       return Loc{utf8.RuneCount(la.lines[numlines-1].data), numlines - 1}
+       return Loc{util.CharacterCount(la.lines[numlines-1].data), numlines - 1}
 }
 
 // LineBytes returns line n as an array of bytes
index ce55f468d32bf49956de0b69b42510d4d2535af0..44f59c788370626074bb7537aa38ff4934b41472 100644 (file)
@@ -1,8 +1,6 @@
 package buffer
 
 import (
-       "unicode/utf8"
-
        "github.com/zyedidia/micro/v2/internal/util"
 )
 
@@ -68,9 +66,9 @@ func DiffLA(a, b Loc, buf *LineArray) int {
        loc := 0
        for i := a.Y + 1; i < b.Y; i++ {
                // + 1 for the newline
-               loc += utf8.RuneCount(buf.LineBytes(i)) + 1
+               loc += util.CharacterCount(buf.LineBytes(i)) + 1
        }
-       loc += utf8.RuneCount(buf.LineBytes(a.Y)) - a.X + b.X + 1
+       loc += util.CharacterCount(buf.LineBytes(a.Y)) - a.X + b.X + 1
        return loc
 }
 
@@ -80,7 +78,7 @@ func (l Loc) right(buf *LineArray) Loc {
                return Loc{l.X + 1, l.Y}
        }
        var res Loc
-       if l.X < utf8.RuneCount(buf.LineBytes(l.Y)) {
+       if l.X < util.CharacterCount(buf.LineBytes(l.Y)) {
                res = Loc{l.X + 1, l.Y}
        } else {
                res = Loc{0, l.Y + 1}
@@ -97,7 +95,7 @@ func (l Loc) left(buf *LineArray) Loc {
        if l.X > 0 {
                res = Loc{l.X - 1, l.Y}
        } else {
-               res = Loc{utf8.RuneCount(buf.LineBytes(l.Y - 1)), l.Y - 1}
+               res = Loc{util.CharacterCount(buf.LineBytes(l.Y - 1)), l.Y - 1}
        }
        return res
 }
index 25b1f38517a6e90b64f6b480a32b9741aefa54cc..5716f22e8e454f2cfb966f8b5701c9aa93b1a49f 100644 (file)
@@ -11,7 +11,6 @@ import (
        "path/filepath"
        "runtime"
        "unicode"
-       "unicode/utf8"
 
        "github.com/zyedidia/micro/v2/internal/config"
        "github.com/zyedidia/micro/v2/internal/screen"
@@ -100,9 +99,9 @@ func (b *Buffer) saveToFile(filename string, withSudo bool) error {
        b.UpdateRules()
        if b.Settings["rmtrailingws"].(bool) {
                for i, l := range b.lines {
-                       leftover := utf8.RuneCount(bytes.TrimRightFunc(l.data, unicode.IsSpace))
+                       leftover := util.CharacterCount(bytes.TrimRightFunc(l.data, unicode.IsSpace))
 
-                       linelen := utf8.RuneCount(l.data)
+                       linelen := util.CharacterCount(l.data)
                        b.Remove(Loc{leftover, i}, Loc{linelen, i})
                }
 
index 9550c01ae681fbb3ddaacae494288dc25739de8a..157f119d3ad5212e37ca256f5ef076544320b41a 100644 (file)
@@ -2,7 +2,6 @@ package buffer
 
 import (
        "regexp"
-       "unicode/utf8"
 
        "github.com/zyedidia/micro/v2/internal/util"
 )
@@ -20,19 +19,19 @@ func (b *Buffer) findDown(r *regexp.Regexp, start, end Loc) ([2]Loc, bool) {
                charpos := 0
 
                if i == start.Y && start.Y == end.Y {
-                       nchars := utf8.RuneCount(l)
+                       nchars := util.CharacterCount(l)
                        start.X = util.Clamp(start.X, 0, nchars)
                        end.X = util.Clamp(end.X, 0, nchars)
                        l = util.SliceStart(l, end.X)
                        l = util.SliceEnd(l, start.X)
                        charpos = start.X
                } else if i == start.Y {
-                       nchars := utf8.RuneCount(l)
+                       nchars := util.CharacterCount(l)
                        start.X = util.Clamp(start.X, 0, nchars)
                        l = util.SliceEnd(l, start.X)
                        charpos = start.X
                } else if i == end.Y {
-                       nchars := utf8.RuneCount(l)
+                       nchars := util.CharacterCount(l)
                        end.X = util.Clamp(end.X, 0, nchars)
                        l = util.SliceStart(l, end.X)
                }
@@ -61,19 +60,19 @@ func (b *Buffer) findUp(r *regexp.Regexp, start, end Loc) ([2]Loc, bool) {
                charpos := 0
 
                if i == start.Y && start.Y == end.Y {
-                       nchars := utf8.RuneCount(l)
+                       nchars := util.CharacterCount(l)
                        start.X = util.Clamp(start.X, 0, nchars)
                        end.X = util.Clamp(end.X, 0, nchars)
                        l = util.SliceStart(l, end.X)
                        l = util.SliceEnd(l, start.X)
                        charpos = start.X
                } else if i == start.Y {
-                       nchars := utf8.RuneCount(l)
+                       nchars := util.CharacterCount(l)
                        start.X = util.Clamp(start.X, 0, nchars)
                        l = util.SliceEnd(l, start.X)
                        charpos = start.X
                } else if i == end.Y {
-                       nchars := utf8.RuneCount(l)
+                       nchars := util.CharacterCount(l)
                        end.X = util.Clamp(end.X, 0, nchars)
                        l = util.SliceStart(l, end.X)
                }
@@ -163,12 +162,12 @@ func (b *Buffer) ReplaceRegex(start, end Loc, search *regexp.Regexp, replace []b
                                result = search.Expand(result, replace, in, submatches)
                        }
                        found++
-                       netrunes += utf8.RuneCount(in) - utf8.RuneCount(result)
+                       netrunes += util.CharacterCount(in) - util.CharacterCount(result)
                        return result
                })
 
                from := Loc{charpos, i}
-               to := Loc{charpos + utf8.RuneCount(l), i}
+               to := Loc{charpos + util.CharacterCount(l), i}
 
                deltas = append(deltas, Delta{newText, from, to})
        }
index c3e016f7ef29f6e45de82e474a23d3447dd1a939..32662be2ca77f4dd37f618f29b5a56f03eb6eed4 100644 (file)
@@ -1,8 +1,6 @@
 package display
 
 import (
-       "unicode/utf8"
-
        runewidth "github.com/mattn/go-runewidth"
        "github.com/zyedidia/micro/v2/internal/buffer"
        "github.com/zyedidia/micro/v2/internal/config"
@@ -70,7 +68,7 @@ func (i *InfoWindow) IsActive() bool   { return true }
 func (i *InfoWindow) LocFromVisual(vloc buffer.Loc) buffer.Loc {
        c := i.Buffer.GetActiveCursor()
        l := i.Buffer.LineBytes(0)
-       n := utf8.RuneCountInString(i.Msg)
+       n := util.CharacterCountInString(i.Msg)
        return buffer.Loc{c.GetCharPosInLine(l, vloc.X-n), 0}
 }
 
@@ -86,7 +84,7 @@ func (i *InfoWindow) displayBuffer() {
        activeC := b.GetActiveCursor()
 
        blocX := 0
-       vlocX := utf8.RuneCountInString(i.Msg)
+       vlocX := util.CharacterCountInString(i.Msg)
 
        tabsize := 4
        line, nColsBeforeStart, bslice := util.SliceVisualEnd(line, blocX, tabsize)
@@ -192,7 +190,7 @@ func (i *InfoWindow) scrollToSuggestion() {
        s := i.totalSize()
 
        for j, n := range i.Suggestions {
-               c := utf8.RuneCountInString(n)
+               c := util.CharacterCountInString(n)
                if j == i.CurSuggestion {
                        if x+c >= i.hscroll+i.Width {
                                i.hscroll = util.Clamp(x+c+1-i.Width, 0, s-i.Width)
index 63ac9c99bb6f26126a943b211e443cabae725d20..5c5f551280d1e4b972979b4c1eb3c255a666cbd9 100644 (file)
@@ -6,7 +6,6 @@ import (
        "regexp"
        "strconv"
        "strings"
-       "unicode/utf8"
 
        luar "layeh.com/gopher-luar"
 
@@ -168,8 +167,8 @@ func (s *StatusLine) Display() {
                statusLineStyle = style
        }
 
-       leftLen := util.StringWidth(leftText, utf8.RuneCount(leftText), 1)
-       rightLen := util.StringWidth(rightText, utf8.RuneCount(rightText), 1)
+       leftLen := util.StringWidth(leftText, util.CharacterCount(leftText), 1)
+       rightLen := util.StringWidth(rightText, util.CharacterCount(rightText), 1)
 
        winX := s.win.X
        for x := 0; x < s.win.Width; x++ {
index c16747a3a6f50a807c7ef36b744ffc40220ecc09..6263586d4450c0eaac438b66b81af45e571ae1f2 100644 (file)
@@ -1,8 +1,6 @@
 package display
 
 import (
-       "unicode/utf8"
-
        runewidth "github.com/mattn/go-runewidth"
        "github.com/zyedidia/micro/v2/internal/buffer"
        "github.com/zyedidia/micro/v2/internal/config"
@@ -34,7 +32,7 @@ func (w *TabWindow) LocFromVisual(vloc buffer.Loc) int {
 
        for i, n := range w.Names {
                x++
-               s := utf8.RuneCountInString(n)
+               s := util.CharacterCountInString(n)
                if vloc.Y == w.Y && vloc.X < x+s {
                        return i
                }
@@ -75,7 +73,7 @@ func (w *TabWindow) SetActive(a int) {
        s := w.TotalSize()
 
        for i, n := range w.Names {
-               c := utf8.RuneCountInString(n)
+               c := util.CharacterCountInString(n)
                if i == a {
                        if x+c >= w.hscroll+w.Width {
                                w.hscroll = util.Clamp(x+c+1-w.Width, 0, s-w.Width)
index ec161bcd92f7cdda0d4bc40b4d7ef089e9cade01..6250fea906c18046d0f1d811262e8733fdef5a20 100644 (file)
@@ -1,8 +1,6 @@
 package display
 
 import (
-       "unicode/utf8"
-
        "github.com/zyedidia/micro/v2/internal/buffer"
        "github.com/zyedidia/micro/v2/internal/config"
        "github.com/zyedidia/micro/v2/internal/screen"
@@ -99,7 +97,7 @@ func (w *TermWindow) Display() {
                }
 
                text := []byte(w.Name())
-               textLen := utf8.RuneCount(text)
+               textLen := util.CharacterCount(text)
                for x := 0; x < w.Width; x++ {
                        if x < textLen {
                                r, combc, size := util.DecodeCharacter(text)
index 98a17c4282546b4fe67c7a025530fe9a3b769078..477bc691603301d2356236fc8147a00858bff33c 100644 (file)
@@ -16,7 +16,6 @@ var combining = &unicode.RangeTable{
        },
 }
 
-
 // DecodeCharacter returns the next character from an array of bytes
 // A character is a rune along with any accompanying combining runes
 func DecodeCharacter(b []byte) (rune, []rune, int) {
@@ -32,7 +31,7 @@ func DecodeCharacter(b []byte) (rune, []rune, int) {
                b = b[s:]
                c, s = utf8.DecodeRune(b)
        }
-       
+
        return r, combc, size
 }