mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 20:11:17 +00:00
Switch to <* *> docs. Fix issue with dynamically loaded C3 libs with other C3 code.
This commit is contained in:
committed by
Christoffer Lerno
parent
9f6a4eb300
commit
31cd839063
@@ -33,11 +33,11 @@ fault NumberConversion
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return a temporary ZString created using the formatting function.
|
||||
*
|
||||
* @param [in] fmt `The formatting string`
|
||||
**/
|
||||
<*
|
||||
Return a temporary ZString created using the formatting function.
|
||||
|
||||
@param [in] fmt `The formatting string`
|
||||
*>
|
||||
fn ZString tformat_zstr(String fmt, args...)
|
||||
{
|
||||
DString str = dstring::temp_with_capacity(fmt.len + args.len * 8);
|
||||
@@ -45,12 +45,12 @@ fn ZString tformat_zstr(String fmt, args...)
|
||||
return str.zstr_view();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a new String created using the formatting function.
|
||||
*
|
||||
* @param [inout] allocator `The allocator to use`
|
||||
* @param [in] fmt `The formatting string`
|
||||
**/
|
||||
<*
|
||||
Return a new String created using the formatting function.
|
||||
|
||||
@param [inout] allocator `The allocator to use`
|
||||
@param [in] fmt `The formatting string`
|
||||
*>
|
||||
fn String format(String fmt, args..., Allocator allocator)
|
||||
{
|
||||
@pool(allocator)
|
||||
@@ -61,18 +61,18 @@ fn String format(String fmt, args..., Allocator allocator)
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a heap allocated String created using the formatting function.
|
||||
*
|
||||
* @param [in] fmt `The formatting string`
|
||||
**/
|
||||
<*
|
||||
Return a heap allocated String created using the formatting function.
|
||||
|
||||
@param [in] fmt `The formatting string`
|
||||
*>
|
||||
fn String new_format(String fmt, args..., Allocator allocator = null) => format(fmt, ...args, allocator: allocator ?: allocator::heap());
|
||||
|
||||
/**
|
||||
* Return a temporary String created using the formatting function.
|
||||
*
|
||||
* @param [in] fmt `The formatting string`
|
||||
**/
|
||||
<*
|
||||
Return a temporary String created using the formatting function.
|
||||
|
||||
@param [in] fmt `The formatting string`
|
||||
*>
|
||||
fn String tformat(String fmt, args...)
|
||||
{
|
||||
DString str = dstring::temp_with_capacity(fmt.len + args.len * 8);
|
||||
@@ -80,12 +80,12 @@ fn String tformat(String fmt, args...)
|
||||
return str.str_view();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a new ZString created using the formatting function.
|
||||
*
|
||||
* @param [in] fmt `The formatting string`
|
||||
* @param [inout] allocator `The allocator to use`
|
||||
**/
|
||||
<*
|
||||
Return a new ZString created using the formatting function.
|
||||
|
||||
@param [in] fmt `The formatting string`
|
||||
@param [inout] allocator `The allocator to use`
|
||||
*>
|
||||
fn ZString new_format_zstr(String fmt, args..., Allocator allocator = allocator::heap())
|
||||
{
|
||||
@pool(allocator)
|
||||
@@ -96,14 +96,14 @@ fn ZString new_format_zstr(String fmt, args..., Allocator allocator = allocator:
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a character is in a set.
|
||||
*
|
||||
* @param c `the character to check`
|
||||
* @param [in] set `The formatting string`
|
||||
* @pure
|
||||
* @return `True if a character is in the set`
|
||||
**/
|
||||
<*
|
||||
Check if a character is in a set.
|
||||
|
||||
@param c `the character to check`
|
||||
@param [in] set `The formatting string`
|
||||
@pure
|
||||
@return `True if a character is in the set`
|
||||
*>
|
||||
macro bool char_in_set(char c, String set)
|
||||
{
|
||||
foreach (ch : set) if (ch == c) return true;
|
||||
@@ -135,14 +135,14 @@ fn String join_new(String[] s, String joiner, Allocator allocator = allocator::h
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove characters from the front and end of a string.
|
||||
*
|
||||
* @param [in] string `The string to trim`
|
||||
* @param [in] to_trim `The set of characters to trim, defaults to whitespace`
|
||||
* @pure
|
||||
* @return `a substring of the string passed in`
|
||||
**/
|
||||
<*
|
||||
Remove characters from the front and end of a string.
|
||||
|
||||
@param [in] string `The string to trim`
|
||||
@param [in] to_trim `The set of characters to trim, defaults to whitespace`
|
||||
@pure
|
||||
@return `a substring of the string passed in`
|
||||
*>
|
||||
fn String String.trim(string, String to_trim = "\t\n\r ")
|
||||
{
|
||||
usz start = 0;
|
||||
@@ -154,14 +154,14 @@ fn String String.trim(string, String to_trim = "\t\n\r ")
|
||||
return string[start..end];
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the String starts with the needle.
|
||||
*
|
||||
* @param [in] string
|
||||
* @param [in] needle
|
||||
* @pure
|
||||
* @return `'true' if the string starts with the needle`
|
||||
**/
|
||||
<*
|
||||
Check if the String starts with the needle.
|
||||
|
||||
@param [in] string
|
||||
@param [in] needle
|
||||
@pure
|
||||
@return `'true' if the string starts with the needle`
|
||||
*>
|
||||
fn bool String.starts_with(string, String needle)
|
||||
{
|
||||
if (needle.len > string.len) return false;
|
||||
@@ -169,14 +169,14 @@ fn bool String.starts_with(string, String needle)
|
||||
return string[:needle.len] == needle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the String ends with the needle.
|
||||
*
|
||||
* @param [in] string
|
||||
* @param [in] needle
|
||||
* @pure
|
||||
* @return `'true' if the string ends with the needle`
|
||||
**/
|
||||
<*
|
||||
Check if the String ends with the needle.
|
||||
|
||||
@param [in] string
|
||||
@param [in] needle
|
||||
@pure
|
||||
@return `'true' if the string ends with the needle`
|
||||
*>
|
||||
fn bool String.ends_with(string, String needle)
|
||||
{
|
||||
if (needle.len > string.len) return false;
|
||||
@@ -184,28 +184,28 @@ fn bool String.ends_with(string, String needle)
|
||||
return string[^needle.len..] == needle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Strip the front of the string if the prefix exists.
|
||||
*
|
||||
* @param [in] string
|
||||
* @param [in] needle
|
||||
* @pure
|
||||
* @return `the substring with the prefix removed`
|
||||
**/
|
||||
<*
|
||||
Strip the front of the string if the prefix exists.
|
||||
|
||||
@param [in] string
|
||||
@param [in] needle
|
||||
@pure
|
||||
@return `the substring with the prefix removed`
|
||||
*>
|
||||
fn String String.strip(string, String needle)
|
||||
{
|
||||
if (!needle.len || !string.starts_with(needle)) return string;
|
||||
return string[needle.len..];
|
||||
}
|
||||
|
||||
/**
|
||||
* Strip the end of the string if the suffix exists.
|
||||
*
|
||||
* @param [in] string
|
||||
* @param [in] needle
|
||||
* @pure
|
||||
* @return `the substring with the suffix removed`
|
||||
**/
|
||||
<*
|
||||
Strip the end of the string if the suffix exists.
|
||||
|
||||
@param [in] string
|
||||
@param [in] needle
|
||||
@pure
|
||||
@return `the substring with the suffix removed`
|
||||
*>
|
||||
fn String String.strip_end(string, String needle)
|
||||
{
|
||||
if (!needle.len || !string.ends_with(needle)) return string;
|
||||
@@ -213,16 +213,16 @@ fn String String.strip_end(string, String needle)
|
||||
return string[:(string.len - needle.len)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Split a string into parts, e.g "a|b|c" split with "|" yields { "a", "b", "c" }
|
||||
*
|
||||
* @param [in] s
|
||||
* @param [in] needle
|
||||
* @param [&inout] allocator "The allocator to use for the String[]"
|
||||
* @param max "Max number of elements, 0 means no limit, defaults to 0"
|
||||
* @require needle.len > 0 "The needle must be at least 1 character long"
|
||||
* @ensure return.len > 0
|
||||
**/
|
||||
<*
|
||||
Split a string into parts, e.g "a|b|c" split with "|" yields { "a", "b", "c" }
|
||||
|
||||
@param [in] s
|
||||
@param [in] needle
|
||||
@param [&inout] allocator "The allocator to use for the String[]"
|
||||
@param max "Max number of elements, 0 means no limit, defaults to 0"
|
||||
@require needle.len > 0 "The needle must be at least 1 character long"
|
||||
@ensure return.len > 0
|
||||
*>
|
||||
fn String[] String.split(s, String needle, usz max = 0, Allocator allocator = allocator::heap())
|
||||
{
|
||||
usz capacity = 16;
|
||||
@@ -253,51 +253,51 @@ fn String[] String.split(s, String needle, usz max = 0, Allocator allocator = al
|
||||
return holder[:i];
|
||||
}
|
||||
|
||||
/**
|
||||
* Split a string into parts, e.g "a|b|c" split with "|" yields { "a", "b", "c" }, using the heap allocator
|
||||
* to store the parts.
|
||||
*
|
||||
* @param [in] s
|
||||
* @param [in] needle
|
||||
* @param max "Max number of elements, 0 means no limit, defaults to 0"
|
||||
* @require needle.len > 0 "The needle must be at least 1 character long"
|
||||
* @ensure return.len > 0
|
||||
**/
|
||||
<*
|
||||
Split a string into parts, e.g "a|b|c" split with "|" yields { "a", "b", "c" }, using the heap allocator
|
||||
to store the parts.
|
||||
|
||||
@param [in] s
|
||||
@param [in] needle
|
||||
@param max "Max number of elements, 0 means no limit, defaults to 0"
|
||||
@require needle.len > 0 "The needle must be at least 1 character long"
|
||||
@ensure return.len > 0
|
||||
*>
|
||||
fn String[] String.new_split(s, String needle, usz max = 0) => s.split(needle, max, allocator::heap()) @inline;
|
||||
|
||||
/**
|
||||
* This function is identical to String.split, but implicitly uses the
|
||||
* temporary allocator.
|
||||
*
|
||||
* @param [in] s
|
||||
* @param [in] needle
|
||||
* @param max "Max number of elements, 0 means no limit, defaults to 0"
|
||||
**/
|
||||
<*
|
||||
This function is identical to String.split, but implicitly uses the
|
||||
temporary allocator.
|
||||
|
||||
@param [in] s
|
||||
@param [in] needle
|
||||
@param max "Max number of elements, 0 means no limit, defaults to 0"
|
||||
*>
|
||||
fn String[] String.tsplit(s, String needle, usz max = 0) => s.split(needle, max, allocator::temp()) @inline;
|
||||
|
||||
/**
|
||||
* Check if a substring is found in the string.
|
||||
<*
|
||||
Check if a substring is found in the string.
|
||||
|
||||
* @param [in] s
|
||||
* @param [in] needle "The string to look for."
|
||||
* @pure
|
||||
* @return "true if the string contains the substring, false otherwise"
|
||||
**/
|
||||
@param [in] s
|
||||
@param [in] needle "The string to look for."
|
||||
@pure
|
||||
@return "true if the string contains the substring, false otherwise"
|
||||
*>
|
||||
fn bool String.contains(s, String needle)
|
||||
{
|
||||
return @ok(s.index_of(needle));
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the index of the first incidence of a string.
|
||||
*
|
||||
* @param [in] s
|
||||
* @param needle "The character to look for"
|
||||
* @pure
|
||||
* @ensure return < s.len
|
||||
* @return "the index of the needle"
|
||||
* @return! SearchResult.MISSING "if the needle cannot be found"
|
||||
**/
|
||||
<*
|
||||
Find the index of the first incidence of a string.
|
||||
|
||||
@param [in] s
|
||||
@param needle "The character to look for"
|
||||
@pure
|
||||
@ensure return < s.len
|
||||
@return "the index of the needle"
|
||||
@return! SearchResult.MISSING "if the needle cannot be found"
|
||||
*>
|
||||
fn usz! String.index_of_char(s, char needle)
|
||||
{
|
||||
foreach (i, c : s)
|
||||
@@ -307,17 +307,17 @@ fn usz! String.index_of_char(s, char needle)
|
||||
return SearchResult.MISSING?;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the index of the first incidence of a character.
|
||||
*
|
||||
* @param [in] s
|
||||
* @param needle "The character to look for"
|
||||
* @param start_index "The index to start with, may exceed max index."
|
||||
* @pure
|
||||
* @ensure return < s.len
|
||||
* @return "the index of the needle"
|
||||
* @return! SearchResult.MISSING "if the needle cannot be found starting from the start_index"
|
||||
**/
|
||||
<*
|
||||
Find the index of the first incidence of a character.
|
||||
|
||||
@param [in] s
|
||||
@param needle "The character to look for"
|
||||
@param start_index "The index to start with, may exceed max index."
|
||||
@pure
|
||||
@ensure return < s.len
|
||||
@return "the index of the needle"
|
||||
@return! SearchResult.MISSING "if the needle cannot be found starting from the start_index"
|
||||
*>
|
||||
fn usz! String.index_of_char_from(s, char needle, usz start_index)
|
||||
{
|
||||
usz len = s.len;
|
||||
@@ -329,16 +329,16 @@ fn usz! String.index_of_char_from(s, char needle, usz start_index)
|
||||
return SearchResult.MISSING?;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the index of the first incidence of a character starting from the end.
|
||||
*
|
||||
* @param [in] s
|
||||
* @param needle "the character to find"
|
||||
* @pure
|
||||
* @ensure return < s.len
|
||||
* @return "the index of the needle"
|
||||
* @return! SearchResult.MISSING "if the needle cannot be found"
|
||||
**/
|
||||
<*
|
||||
Find the index of the first incidence of a character starting from the end.
|
||||
|
||||
@param [in] s
|
||||
@param needle "the character to find"
|
||||
@pure
|
||||
@ensure return < s.len
|
||||
@return "the index of the needle"
|
||||
@return! SearchResult.MISSING "if the needle cannot be found"
|
||||
*>
|
||||
fn usz! String.rindex_of_char(s, char needle)
|
||||
{
|
||||
foreach_r (i, c : s)
|
||||
@@ -348,17 +348,17 @@ fn usz! String.rindex_of_char(s, char needle)
|
||||
return SearchResult.MISSING?;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the index of the first incidence of a string.
|
||||
*
|
||||
* @param [in] s
|
||||
* @param [in] needle
|
||||
* @pure
|
||||
* @ensure return < s.len
|
||||
* @require needle.len > 0 : "The needle must be len 1 or more"
|
||||
* @return "the index of the needle"
|
||||
* @return! SearchResult.MISSING "if the needle cannot be found"
|
||||
**/
|
||||
<*
|
||||
Find the index of the first incidence of a string.
|
||||
|
||||
@param [in] s
|
||||
@param [in] needle
|
||||
@pure
|
||||
@ensure return < s.len
|
||||
@require needle.len > 0 : "The needle must be len 1 or more"
|
||||
@return "the index of the needle"
|
||||
@return! SearchResult.MISSING "if the needle cannot be found"
|
||||
*>
|
||||
fn usz! String.index_of(s, String needle)
|
||||
{
|
||||
usz needed = needle.len;
|
||||
@@ -373,17 +373,17 @@ fn usz! String.index_of(s, String needle)
|
||||
return SearchResult.MISSING?;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the index of the last incidence of a string.
|
||||
*
|
||||
* @param [in] s
|
||||
* @param [in] needle
|
||||
* @pure
|
||||
* @ensure return < s.len
|
||||
* @require needle.len > 0 "The needle must be len 1 or more"
|
||||
* @return "the index of the needle"
|
||||
* @return! SearchResult.MISSING "if the needle cannot be found"
|
||||
**/
|
||||
<*
|
||||
Find the index of the last incidence of a string.
|
||||
|
||||
@param [in] s
|
||||
@param [in] needle
|
||||
@pure
|
||||
@ensure return < s.len
|
||||
@require needle.len > 0 "The needle must be len 1 or more"
|
||||
@return "the index of the needle"
|
||||
@return! SearchResult.MISSING "if the needle cannot be found"
|
||||
*>
|
||||
fn usz! String.rindex_of(s, String needle)
|
||||
{
|
||||
usz needed = needle.len;
|
||||
@@ -476,12 +476,12 @@ fn String ZString.tcopy(z)
|
||||
return z.str_view().copy(allocator::temp()) @inline;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert an UTF-8 string to UTF-16
|
||||
* @return "The UTF-16 string as a slice, allocated using the given allocator"
|
||||
* @return! UnicodeResult.INVALID_UTF8 "If the string contained an invalid UTF-8 sequence"
|
||||
* @return! AllocationFailure "If allocation of the string fails"
|
||||
**/
|
||||
<*
|
||||
Convert an UTF-8 string to UTF-16
|
||||
@return "The UTF-16 string as a slice, allocated using the given allocator"
|
||||
@return! UnicodeResult.INVALID_UTF8 "If the string contained an invalid UTF-8 sequence"
|
||||
@return! AllocationFailure "If allocation of the string fails"
|
||||
*>
|
||||
fn Char16[]! String.to_new_utf16(s, Allocator allocator = allocator::heap())
|
||||
{
|
||||
usz len16 = conv::utf16len_for_utf8(s);
|
||||
@@ -491,12 +491,12 @@ fn Char16[]! String.to_new_utf16(s, Allocator allocator = allocator::heap())
|
||||
return data[:len16];
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert an UTF-8 string to UTF-16
|
||||
* @return "The UTF-16 string as a slice, allocated using the given allocator"
|
||||
* @return! UnicodeResult.INVALID_UTF8 "If the string contained an invalid UTF-8 sequence"
|
||||
* @return! AllocationFailure "If allocation of the string fails"
|
||||
**/
|
||||
<*
|
||||
Convert an UTF-8 string to UTF-16
|
||||
@return "The UTF-16 string as a slice, allocated using the given allocator"
|
||||
@return! UnicodeResult.INVALID_UTF8 "If the string contained an invalid UTF-8 sequence"
|
||||
@return! AllocationFailure "If allocation of the string fails"
|
||||
*>
|
||||
fn Char16[]! String.to_temp_utf16(s)
|
||||
{
|
||||
return s.to_new_utf16(allocator::temp());
|
||||
@@ -522,12 +522,12 @@ fn Char32[]! String.to_utf32(s, Allocator allocator)
|
||||
fn Char32[]! String.to_new_utf32(s) => s.to_utf32(allocator::heap()) @inline;
|
||||
fn Char32[]! String.to_temp_utf32(s) => s.to_utf32(allocator::temp()) @inline;
|
||||
|
||||
/**
|
||||
* Convert a string to ASCII lower case.
|
||||
*
|
||||
* @param [inout] s
|
||||
* @pure
|
||||
**/
|
||||
<*
|
||||
Convert a string to ASCII lower case.
|
||||
|
||||
@param [inout] s
|
||||
@pure
|
||||
*>
|
||||
fn void String.convert_ascii_to_lower(s)
|
||||
{
|
||||
foreach (&c : s) if (c.is_upper() @pure) *c += 'a' - 'A';
|
||||
@@ -545,25 +545,25 @@ fn String String.temp_ascii_to_lower(s)
|
||||
return s.new_ascii_to_lower(allocator::temp());
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a string to ASCII upper case.
|
||||
*
|
||||
* @param [inout] s
|
||||
* @pure
|
||||
**/
|
||||
<*
|
||||
Convert a string to ASCII upper case.
|
||||
|
||||
@param [inout] s
|
||||
@pure
|
||||
*>
|
||||
fn void String.convert_ascii_to_upper(s)
|
||||
{
|
||||
foreach (&c : s) if (c.is_lower() @pure) *c -= 'a' - 'A';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string converted to ASCII upper case.
|
||||
*
|
||||
* @param [in] s
|
||||
* @param [inout] allocator
|
||||
*
|
||||
* @return `a new String converted to ASCII upper case.`
|
||||
**/
|
||||
<*
|
||||
Returns a string converted to ASCII upper case.
|
||||
|
||||
@param [in] s
|
||||
@param [inout] allocator
|
||||
|
||||
@return `a new String converted to ASCII upper case.`
|
||||
*>
|
||||
fn String String.new_ascii_to_upper(s, Allocator allocator = allocator::heap())
|
||||
{
|
||||
String copy = s.copy(allocator);
|
||||
@@ -576,10 +576,10 @@ fn StringIterator String.iterator(s)
|
||||
return { s, 0 };
|
||||
}
|
||||
|
||||
/**
|
||||
* @param [in] s
|
||||
* @return `a temporary String converted to ASCII upper case.`
|
||||
**/
|
||||
<*
|
||||
@param [in] s
|
||||
@return `a temporary String converted to ASCII upper case.`
|
||||
*>
|
||||
fn String String.temp_ascii_to_upper(s)
|
||||
{
|
||||
return s.new_ascii_to_upper(allocator::temp());
|
||||
@@ -627,9 +627,9 @@ fn usz String.utf8_codepoints(s)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @require (base <= 10 && base > 1) || base == 16 : "Unsupported base"
|
||||
**/
|
||||
<*
|
||||
@require (base <= 10 && base > 1) || base == 16 : "Unsupported base"
|
||||
*>
|
||||
macro String.to_integer(string, $Type, int base = 10)
|
||||
{
|
||||
usz len = string.len;
|
||||
|
||||
Reference in New Issue
Block a user