vlib: fix remaining mutability errors

This commit is contained in:
Alexander Medvednikov 2019-12-07 15:13:23 +03:00
parent 329485d4b6
commit c2814c1ada
3 changed files with 20 additions and 21 deletions

View file

@ -25,25 +25,25 @@ const (
*/
pub fn decode(data string) string {
buffer := malloc( data.len * 3 / 4 )
return tos(buffer, decode_in_buffer(data, mut buffer) )
return tos(buffer, decode_in_buffer(data, buffer) )
}
/**
* decode - expects a string. Returns its base64 encoded version.
* @param data - the input string.
* @return the base64 encoded version of the input string.
* @return the base64 encoded version of the input string.
* NB: base64 encoding returns a string that is ~ 4/3 larger than the input.
* NB: if you need to encode many strings repeatedly, take a look at encode_in_buffer too.
*/
pub fn encode(data string) string {
buffer := malloc( 4 * ((data.len + 2) / 3) )
return tos(buffer, encode_in_buffer(data, mut buffer))
return tos(buffer, encode_in_buffer(data, buffer))
}
/**
* decode_in_buffer - expects a string reference, and a buffer in which to store its decoded version.
* @param data - a reference/pointer to the input string that will be decoded.
* @param buffer - a reference/pointer to the buffer that will hold the result.
* @param buffer - a reference/pointer to the buffer that will hold the result.
* The buffer should be large enough (i.e. 3/4 of the data.len, or larger) to hold the decoded data.
* @return the actual size of the decoded data in the buffer.
* NB: this function does NOT allocate new memory, and is suitable for handling very large strings.
@ -104,12 +104,12 @@ pub fn decode_in_buffer(data &string, buffer byteptr) int {
/**
* encode_in_buffer - expects a string reference, and a buffer in which to store its base64 encoded version.
* @param data - a reference/pointer to the input string.
* @param buffer - a reference/pointer to the buffer that will hold the result.
* @param buffer - a reference/pointer to the buffer that will hold the result.
* The buffer should be large enough (i.e. 4/3 of the data.len, or larger) to hold the encoded data.
* @return the actual size of the encoded data in the buffer.
* NB: this function does NOT allocate new memory, and is suitable for handling very large strings.
*/
pub fn encode_in_buffer(data &string, buffer mut byteptr) int {
pub fn encode_in_buffer(data &string, buffer byteptr) int {
input_length := data.len
output_length := 4 * ((input_length + 2) / 3)