Sign in

    angela/srt/src does not have a README file

    Piece

    pub(all) struct Piece {
    index : Int
    start : Int
    end : Int
    text : String
    }

    impl Show for Piece

    Piece::new

    fn Piece::new(index : Int, start : Int, end : Int, text : String) -> Piece

    创建一个新的字幕片段。

    参数:
    • index : 字幕片段的序号(从1开始)
    • start : 开始时间,以秒为单位
    • end : 结束时间,以秒为单位
    • text : 字幕内容文本

    返回一个新的Piece实例。

    示例:
    let piece = Piece::new(1, 0, 5, "Hello, World!")
    inspect(piece.index, content="1")
    inspect(piece.start, content="0")
    inspect(piece.end, content="5")
    inspect(piece.text, content="Hello, World!")

    Srt

    pub(all) struct Srt {
    pieces : Array[Piece]
    }

    SRT字幕文件的容器结构体。

    包含一个字幕片段数组,用于存储和管理整个SRT文件的内容。 每个SRT文件由多个按时间顺序排列的字幕片段组成。

    字段:
    • pieces : 字幕片段数组,按时间顺序存储所有字幕片段。
    impl Show for Srt

    Srt::add_piece

    fn Srt::add_piece(self : Srt, piece : Piece) -> Unit

    向SRT文件中添加一个字幕片段。

    参数:
    • self : 要添加字幕片段的SRT文件
    • piece : 要添加的字幕片段

    注意:片段将按添加顺序存储,调用者应确保时间顺序正确。

    示例:
    let srt = Srt::new()
    let piece = Piece::new(1, 0, 5, "Hello")
    srt.add_piece(piece)
    inspect(srt.pieces.length(), content="1")

    Srt::new

    fn Srt::new() -> Srt

    创建一个新的空SRT文件。

    返回一个不包含任何字幕片段的Srt实例。

    示例:
    let srt = Srt::new()
    inspect(srt.pieces.length(), content="0")

    read_lines

    fn read_lines(file_path : String) -> Array[String] raise
    IOError

    从文本文件读取所有行,并进行预处理。

    此函数执行以下操作:
    1. 读取整个文件内容为字符串
    2. 统一换行符为\n(处理Windows的\r\n)
    3. 按换行符分割为行数组
    4. 过滤掉以全角括号开头和结尾的行(通常用于中文注释)

    参数:
    • file_path : 要读取的文件路径

    返回:经过预处理的行数组

    可能抛出的错误:@fs.IOError - 当文件读取失败时

    示例:
    // 假设文件内容为:
    // 第一行
    // (这是注释)
    // 第二行
    let lines = read_lines("example.txt")
    inspect(lines.length(), content="2")
    inspect(lines[0], content="第一行")
    inspect(lines[1], content="第二行")

    write_lines

    fn write_lines(file_path : String, lines : Array[String]) -> Unit raise
    IOError

    将字符串数组写入文件,每行用换行符分隔。

    此函数执行以下操作:
    1. 将字符串数组用\n连接成单个字符串
    2. 将结果字符串写入指定文件

    参数:
    • file_path : 要写入的文件路径
    • lines : 要写入的字符串数组,每个元素将成为文件的一行

    可能抛出的错误:@fs.IOError - 当文件写入失败时

    示例:
    let lines = ["第一行", "第二行", "第三行"]
    write_lines("output.txt", lines)
    // 文件内容将是:
    // 第一行
    // 第二行
    // 第三行

    Source Files