libcrn  3.9.5
A document image processing library
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Types | Public Member Functions | Public Attributes | List of all members
crn::TextFile Class Reference

A text file. More...

#include <CRNTextFile.h>

+ Collaboration diagram for crn::TextFile:

Public Types

enum  Encoding { Encoding::UTF_8, Encoding::UTF_32 }
 Allowed text encoding. More...
 

Public Member Functions

 TextFile (Encoding enc=Encoding::UTF_8)
 Blank constructor. More...
 
 TextFile (const Path &fname, Encoding enc=Encoding::UTF_8)
 File constructor. More...
 
 TextFile (const TextFile &)=delete
 
 TextFile (TextFile &&)=default
 
 ~TextFile ()=default
 Destructor. More...
 
TextFileoperator= (const TextFile &)=delete
 
TextFileoperator= (TextFile &&)=default
 
void Save (const Path &fname)
 Saves a file with the same encoding as when loaded. More...
 
void Save (const Path &fname, Encoding enc)
 Saves a file with specific encoding. More...
 
void Save ()
 Overwrites the loaded file. More...
 
const StringGetText () const noexcept
 Get text content. More...
 
std::vector< StringSplitText () const
 Extract words. More...
 
std::set< StringExtractWords (bool case_sensitive=false) const
 Extract unique words. More...
 
std::map< int, StringExtractWordsByFrequency (bool case_sensitive=false) const
 Extract unique words sorted by frequency. More...
 

Public Attributes

String text
 

Detailed Description

A text file.

A UTF-8 text file.

Author
Yann LEYDIER
Date
24 October 2006
Version
0.3

Definition at line 43 of file CRNTextFile.h.

Member Enumeration Documentation

Allowed text encoding.

Enumerator
UTF_8 
UTF_32 

Definition at line 47 of file CRNTextFile.h.

Constructor & Destructor Documentation

TextFile::TextFile ( Encoding  enc = Encoding::UTF_8)

Blank constructor.

Blank constructor

Parameters
[in]encthe default encoding for writting

Definition at line 35 of file CRNTextFile.cpp.

TextFile::TextFile ( const Path fname,
Encoding  enc = Encoding::UTF_8 
)

File constructor.

File constructor

Exceptions
ExceptionIOcannot open file
Parameters
[in]fnamethe file to load
[in]encthe encoding of the file

Definition at line 48 of file CRNTextFile.cpp.

crn::TextFile::TextFile ( const TextFile )
delete
crn::TextFile::TextFile ( TextFile &&  )
default
crn::TextFile::~TextFile ( )
default

Destructor.

Member Function Documentation

std::set< String > TextFile::ExtractWords ( bool  case_sensitive = false) const

Extract unique words.

Extract unique words

Parameters
[in]case_sensitiveif false, all words are converted to lower case
Returns
a set of words, sorted in alphabetical order

Definition at line 156 of file CRNTextFile.cpp.

std::map< int, String > TextFile::ExtractWordsByFrequency ( bool  case_sensitive = false) const

Extract unique words sorted by frequency.

Extract unique words and sort them from least frequent to most frequent.

If you want to sweep to words from the most frequent to the least frequent, use a reverse_iterator.

Parameters
[in]case_sensitiveif true, all words are converted to lower case
Returns
a map of occurrences and words, sorted from least frequent to most frequent

Definition at line 181 of file CRNTextFile.cpp.

const String& crn::TextFile::GetText ( ) const
inlinenoexcept

Get text content.

Definition at line 69 of file CRNTextFile.h.

TextFile& crn::TextFile::operator= ( const TextFile )
delete
TextFile& crn::TextFile::operator= ( TextFile &&  )
default
void TextFile::Save ( const Path fname)

Saves a file with the same encoding as when loaded.

Saves to file

Exceptions
ExceptionIOcannot open file
Parameters
[in]fnamethe file name

Definition at line 85 of file CRNTextFile.cpp.

void TextFile::Save ( const Path fname,
Encoding  enc 
)

Saves a file with specific encoding.

Saves to file

Exceptions
ExceptionIOcannot open file
Parameters
[in]fnamethe file name
[in]encthe encoding for saving

Definition at line 110 of file CRNTextFile.cpp.

void TextFile::Save ( )

Overwrites the loaded file.

Saves to file

Exceptions
ExceptionIOcannot open file

Definition at line 133 of file CRNTextFile.cpp.

std::vector<String> crn::TextFile::SplitText ( ) const
inline

Extract words.

Definition at line 72 of file CRNTextFile.h.

Member Data Documentation

String crn::TextFile::text

the content of the file

Definition at line 78 of file CRNTextFile.h.


The documentation for this class was generated from the following files: