NAME
Encode::Newlines - Normalize line ending sequences
VERSION
This document describes version 0.02 of Encode::Newlines, released October 7, 2004.
SYNOPSIS
use Encode;
use Encode::Newlines;
# Convert input and output streams to CRLF
open IN, '<:raw:encoding(CRLF)', 'file.txt';
open OUT, '>:raw:encoding(CRLF)', 'file.txt';
# Convert to native newlines
# Note that decode() and encode() are equivalent here
$native = decode(Native => $string);
$native = encode(Native => $string);
# Convert input to LF, and output to Native
open IO, '+<:raw:encoding(LF-Native)', 'file.txt';
{
# Allow mixed newlines in $mixed
local $Encode::Newlines::AllowMixed = 1;
$cr = encode(CR => $mixed);
}
DESCRIPTION
This module provides the CR
, LF
, CRLF
and Native
encodings, to aid in normalizing line endings. It is designed for the SVK version control system to support the svn:eol-style
property.
It converts whatever line endings the source uses to the designated newline sequence, for both encode
and decode
operations.
If you specify two different line endings joined by a -
, it will use the first one for decoding and the second one for encoding. For example, the LF-CRLF
encoding means that all input should be normalized to LF
, and all output should be normalized to CRLF
.
If the source has an inconsistent line ending style, then a Mixed newlines
exception is raised on behalf of the caller. However, if the package variable $Encode::Newlines::AllowMixed
is set to a true value, then it will silently convert all three line endings.
TODO
An optional XS implemenation would be nice.
SEE ALSO
AUTHORS
Autrijus Tang <autrijus@autrijus.org>
COPYRIGHT
Copyright 2004 by Autrijus Tang <autrijus@autrijus.org>.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.