Coder Social home page Coder Social logo

ctmacuser / internetlines Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 26 KB

Parse CRLF-terminated lines from raw data or other character code points

License: MIT License

Swift 100.00%
swift swift-package-manager crlf lines parses-lines newline-character-sequences

internetlines's Introduction

InternetLines

Parse CRLF-terminated lines from raw data or other character code points.

Installation

The library is designed to be used with the Swift Package Manager. Add this library's Git URL as a dependency to your SPM project. Otherwise, manually add the files in the "Sources/InternetLines/" sub-directory to your project.

Usage

The main support type is LineTerminatorSearchTargets, which specifies which line-breaking sequences should be searched for. It's an OptionSet, so multiple sequences can be searched for at once. The current search targets are:

  • CRLF, carriage-return followed by line-feed: The terminator used for text lines passed along for various Internet protocols. It's also used for text files for the Windows operating system family.
  • LF, line-feed only: The terminator used for text files for Unix (and related) operating systems.
  • CR, carriage-return only: A terminator used for text files only for some ancient operating systems, like pre-NeXT macOS.
  • CRCRLF, two carriage-returns and a line-feed: It's not an official terminator, but can appear by mistake when writing text files on Windows systems.

The main functionality is expressed through types that wrap a Sequence or Collection with the right Element type. The element type can be either UnicodeScalar or one of the default integer types. A wrapper object can be obtained through helper methods added as Sequence or Collection extensions:

  • Sequence.parsedLines(considering:) returns a LineSequence, which parses then vends each line from the source sequence as a (data: [Element], terminator: [Element]), where the main part of the line is separated from the terminator upon return. At most one part of a returned tuple is empty.
  • Collection.lineLocations(considering:) returns a LineLocations, which is an (optionally bi-directional) collection that vends (start: Base.Index, border: Base.Index, end: Base.Index), which is a tuple that returns the start and end of each parsed line in the source along with the border between the main part of the line and its terminator.
  • Collection.lineTerminatorLocations(considering:) returns a LineTerminatorLocations, which is an (optionally bi-directional) collection that vends a Range<Base.Index> for each line-breaking sequence within the source, specifying the terminator's location.

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.