cl

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 10, 2022 License: MIT Imports: 6 Imported by: 2

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func CountLines

func CountLines(inputReader io.Reader) (int, error)

CountLines counts the number of lines that contains a line break (LF) in a file.

Example
package main

import (
	"fmt"
	"log"
	"strings"

	"github.com/KEINOS/go-countline/cl"
)

func main() {
	for _, sample := range []struct {
		Input string
	}{
		{""},            // --> 0
		{"Hello"},       // --> 1
		{"Hello\n"},     // --> 1
		{"\n"},          // --> 1
		{"\n\n"},        // --> 2
		{"\nHello"},     // --> 2
		{"\nHello\n"},   // --> 2
		{"\n\nHello"},   // --> 3
		{"\n\nHello\n"}, // --> 3
	} {
		readerFile := strings.NewReader(sample.Input)

		count, err := cl.CountLines(readerFile)
		if err != nil {
			log.Fatal(err)
		}

		fmt.Printf("%#v --> %v\n", sample.Input, count)
	}
}
Output:

"" --> 0
"Hello" --> 1
"Hello\n" --> 1
"\n" --> 1
"\n\n" --> 2
"\nHello" --> 2
"\nHello\n" --> 2
"\n\nHello" --> 3
"\n\nHello\n" --> 3

Types

This section is empty.

Directories

Path Synopsis
This creates a file of 1 GiB in size with lines of random values.
This creates a file of 1 GiB in size with lines of random values.
Package spec provides the test specifications for the CountLines function.
Package spec provides the test specifications for the CountLines function.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL