util

package
v0.0.0-...-d3da680 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 4, 2024 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package util contains utility functions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SplitToChunks

func SplitToChunks(content []byte, maxChunkSize int, lookbackWindow int) ([]string, error)

SplitToChunks splits the contents into chunks, each chunk does not exceed maxChunkSize number of bytes. Assuming the content is encoded in UTF-8. The function will guarantee not to split a multi-byte Unicode into different chunks. The function will attempt to split the chunk as close to maxChunkSize as it can, but it will also prefer splitting at line breaks ("\r\n", otherwise "\r" or "\n"), or whitespaces. It will scan for the last lookbackWindow bytes for line break/white space to split. If there is no linebreak or whitespace within lookbackWindow bytes, it will split the chunk as close to maxChunkSize (without breaking a multi-byte UTF-8 character).

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL