Giter Club home page Giter Club logo

line-break-preserving-line-splitting's Introduction

line-break-preserving-line-splitting

line-break-preserving-line-splitting artifacts CI

Features

  • Streams from a java.io.Reader, so can process very large files
  • Unlike java.io.BufferedReader.readLine(), retains the line-break at the end of the line, whether it's UNIX, Windows, etc
  • Implements the scala.collection.Iterator trait. Lines are not retained in memory after being returned by next().
  • Limits memory consumption to a single ring-buffer the lives the lifetime of the iterator, and, for lines that loop round the ring-buffer, temporary StringBuilder instances that are garbage-collected after the line is returned.
  • Reading a line using next() will return as soon as the java.io.Reader has returned enough characters - will at most only attempt to fill the ring-buffer.

For my purposes, the first two requirements were the most important. If I hadn't wanted to retain the line-breaks, I'd probably have used java.io.BufferedReader.readLine().

Installation

libraryDependencies += "com.madgag" %% "line-break-preserving-line-splitting" % "[version]"

Example usage

import com.madgag.linesplitting._

val splitLines = {
  val reader: java.io.Reader = new java.io.StringReader("Foo\nBar\rBoo")

  val iter = new LineBreakPreservingIterator(reader)
  
  iter.toSeq
}.toSeq
// splitLines: Seq[String] = List(
//   """Foo
// """,
//   """Bar
""",
//   "Boo"
// )

splitLines.map(_.replace("\n", "[LF]").replace("\r", "[CR]"))
// res0: Seq[String] = List("Foo[LF]", "Bar[CR]", "Boo")

line-break-preserving-line-splitting's People

Contributors

rtyley avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

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.