Selfie
Loading...
Searching...
No Matches
selfie_lib.LineReader.LineReader Class Reference

Public Member Functions

 __init__ (self, bytes content)
 
 for_binary (cls, bytes content)
 
 for_string (cls, str content)
 
bool unix_newlines (self)
 
Optional[str] read_line (self)
 
int get_line_number (self)
 

Detailed Description

Definition at line 12 of file LineReader.py.

Constructor & Destructor Documentation

◆ __init__()

selfie_lib.LineReader.LineReader.__init__ (   self,
bytes  content 
)

Definition at line 13 of file LineReader.py.

13 def __init__(self, content: bytes):
14 self.__buffer = io.BytesIO(content)
15 self.__uses_unix_newlines = self.__detect_newline_type()
16 self.__line_count = 0 # Initialize line count
17

Member Function Documentation

◆ for_binary()

selfie_lib.LineReader.LineReader.for_binary (   cls,
bytes  content 
)

Definition at line 19 of file LineReader.py.

19 def for_binary(cls, content: bytes):
20 return cls(content)
21

◆ for_string()

selfie_lib.LineReader.LineReader.for_string (   cls,
str  content 
)

Definition at line 23 of file LineReader.py.

23 def for_string(cls, content: str):
24 return cls(content.encode("utf-8"))
25

◆ get_line_number()

int selfie_lib.LineReader.LineReader.get_line_number (   self)

Definition at line 44 of file LineReader.py.

44 def get_line_number(self) -> int:
45 return self.__line_count

◆ read_line()

Optional[str] selfie_lib.LineReader.LineReader.read_line (   self)

Definition at line 34 of file LineReader.py.

34 def read_line(self) -> Optional[str]:
35 line_bytes = self.__buffer.readline()
36 if line_bytes == b"":
37 return None
38 else:
39 self.__line_count += 1 # Increment line count for each line read
40 line = line_bytes.decode("utf-8")
41 return line.rstrip("\r\n" if not self.__uses_unix_newlines else "\n")
42

◆ unix_newlines()

bool selfie_lib.LineReader.LineReader.unix_newlines (   self)

Definition at line 31 of file LineReader.py.

31 def unix_newlines(self) -> bool:
32 return self.__uses_unix_newlines
33

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