Skip to content

Commit

Permalink
chore: improve readme rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-jerry-ye committed Jan 6, 2025
1 parent d5c9d2c commit bdd0245
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
16 changes: 8 additions & 8 deletions legacy/examples/buffer/README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
# Buffer
## API
Creates a new instance of the Buffer type with the specified initial capacity. The capacity determines the initial size of the buffer to store elements of type T. The type T must implement the Default trait to provide a default value.
```
```moonbit
Buffer::new[T : Default](capacity : Int) -> Buffer[T]
```
Returns the current capacity of the buffer. The capacity represents the maximum number of elements that the buffer can hold without resizing.
```
```moonbit
capacity[T](self : Buffer[T]) -> Int
```
Returns the current number of elements stored in the buffer. This method provides the actual count of elements present in the buffer.
```
```moonbit
length[T](self : Buffer[T]) -> Int
```
Appends an element of type T to the end of the buffer. If the buffer is at its capacity, it may be automatically resized to accommodate the new element.
```
```moonbit
append[T : Default](self : Buffer[T], value : T)
```
Truncates the current buffer and copies the contents of another buffer another into it. The original capacity of the buffer remains unchanged.
```
```moonbit
truncate[T : Default](self : Buffer[T], another : Buffer[T])
```
Clears all elements from the buffer and resets its length to zero. The capacity remains unchanged.
```
```moonbit
clear[T : Default](self : Buffer[T])
```
Resets the buffer by clearing its contents and setting its capacity to the specified value. This is useful when you want to reuse an existing buffer with a different capacity.
```
```moonbit
reset[T : Default](self : Buffer[T], capacity : Int)
```
Prints the contents of the buffer to the standard output using the Show trait. The Show trait must be implemented for type T in order to use this method.
```
```moonbit
println[T : Show](self: Buffer[T])
```
18 changes: 9 additions & 9 deletions legacy/examples/bytes-buffer/README.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
# Bytes-Buffer
## API
```
```moonbit
pub func Buffer::new(size : Int) -> Buffer
```
Creates a new buffer with the specified size.
```
```moonbit
pub func capacity(self : Buffer) -> Int
```
Returns the total capacity of the buffer.
```
```moonbit
pub func length(self : Buffer) -> Int
```
Returns the current length of the buffer.
```
```moonbit
pub func append_int(self : Buffer, value : Int)
```
Appends an integer value to the buffer.
```
```moonbit
pub func truncate(self : Buffer, another: Buffer)
```
Truncates the buffer and replaces its content with the content of another buffer.
```
```moonbit
pub func clear(self : Buffer)
```
Clears the content of the buffer.
```
```moonbit
pub func reset(self : Buffer, capacity : Int)
```
Resets the buffer with a new capacity.
```
```moonbit
pub func to_bytes(self : Buffer) -> Bytes
```
Converts the buffer content to bytes.
```
```moonbit
pub func bytes_to_int(bytes : Bytes, start : Int) -> Int
```
Converts a section of bytes to an integer.
Expand Down
18 changes: 9 additions & 9 deletions legacy/examples/char/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,38 @@ Use Moonbit to implement string tools.

## API
This function is used to check whether the given character c is a valid character. It returns a boolean value indicating whether the character is valid or not.
```
```moonbit
is_valid(c: Char) -> Bool
```
This function is used to determine if the character c is an alphabet letter. It returns true if c is an alphabet letter, otherwise it returns false.
```
```moonbit
is_alpha(c : Char) -> Bool
```
This function is used to check if the character c is a numeric digit. It returns true if c is a numeric digit, otherwise it returns false.
```
```moonbit
is_numeric(c : Char) -> Bool
```
This function is used to determine if the character c is either an alphabet letter or a numeric digit. It returns true if c is an alphanumeric character, otherwise it returns false.
```
```moonbit
is_alphanumeric(c : Char) -> Bool
```
This function is used to convert the character c to its lowercase form and returns the lowercase character.
```
```moonbit
to_lower(c : Char) -> Char
```
This function is used to convert the character c to its uppercase form and returns the uppercase character.
```
```moonbit
to_upper(c : Char) -> Char
```
This function is used to check if the character c is a whitespace character (such as space or tab). It returns true if c is a whitespace character, otherwise it returns false.
```
```moonbit
is_whitespace(c : Char) -> Bool
```
This function returns the next character following the character c. If there is a next character, it returns the character wrapped in Some, otherwise it returns None.
```
```moonbit
next(c : Char) -> Option[Char]
```
This function returns the previous character before the character c. If there is a previous character, it returns the character wrapped in Some, otherwise it returns None.
```
```moonbit
prev(c : Char) -> Option[Char]
```

0 comments on commit bdd0245

Please sign in to comment.