-
Notifications
You must be signed in to change notification settings - Fork 0
Dev #30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
davidgaspardev
wants to merge
9
commits into
main
Choose a base branch
from
dev
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Dev #30
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7eac1f4
Merge pull request #26 from davidgaspardev/main
davidgaspardev c630f58
fix: update README.md for clarity and consistency in character array …
davidgaspardev 38a81b3
chore: Update type from ubyte_t to byte_t for consistency in equal fu…
davidgaspardev 2c7125a
feat: rename library from cbytes to bytekit and update related refere…
davidgaspardev 563a7a1
Merge pull request #28 from davidgaspardev/enhancement/rename
davidgaspardev 1bc9b3b
feat: add test_equal target and corresponding test_equal.c file
davidgaspardev b559294
cleanup: Remove unused include stdio.h
davidgaspardev ff11023
chore: Update library name
davidgaspardev f783c6c
Merge pull request #29 from davidgaspardev/boot/test-equal
davidgaspardev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,39 +1,45 @@ | ||
| # cBytes | ||
| # bytekit | ||
|
|
||
| Char bytes is based on a series of uniformly creasing addresses, to which each address has a binary value and that value corresponds to character in the **ASCII table**. | ||
| **bytekit** is a C library for manipulating character arrays (strings) as sequences of bytes, where each address holds a binary value corresponding to a character in the ASCII table. | ||
|
|
||
| --- | ||
|
|
||
| ## Character array and character pointer | ||
| ## Character array vs. character pointer | ||
|
|
||
| What is the difference between character array and character pointer ? </br> | ||
| What is the difference between a character array and a character pointer? | ||
| Consider the following example: | ||
|
|
||
| ```c | ||
| char arr[] = "Hello World"; // array version | ||
| char ptr* = "Hello World"; // pointer version | ||
| char *ptr = "Hello World"; // pointer version | ||
| ``` | ||
| The type of both the variables is a pointer to `char` or `(char\*)`, so you can pass either of them to a function whose formal argument accepts an array of characters or character pointer. In C programming, the name of an array always points to the base address, roughly speaking, an array is a pointer. | ||
|
|
||
| Here are differences: | ||
| - 1 `arr` is an array of `12` characters. When compiler sees the statement: | ||
| - `arr` is an array of 12 characters. When the compiler sees: | ||
| ```c | ||
| char arr[] = "Hello World"; | ||
| ``` | ||
| It allocates `12` consecutive bytes of memory and associates the address of the first allocated byte with `arr`. | ||
| it allocates 12 consecutive bytes of memory and associates the address of the first byte with `arr`. | ||
|  | ||
| On the other hand when the compiler sees the statement. | ||
|
|
||
| - `ptr` is a pointer to a string literal. When the compiler sees: | ||
| ```c | ||
| char ptr* = "Hello World"; | ||
| char *ptr = "Hello World"; | ||
| ``` | ||
| It allocates `12` consecutive bytes for string literal `"Hello World"` and `4` extra bytes for pointer variable `ptr`. And assigns the address of the string literal to `ptr`. So, in this case, a total of `16` bytes are allocated. | ||
| it allocates 12 bytes for the string literal `"Hello World"` (in read-only memory) and extra bytes for the pointer variable `ptr`. The pointer is assigned the address of the string literal. | ||
|  | ||
|
|
||
| ## This library | ||
| In C, the name of an array points to the base address, but an array and a pointer are not the same: | ||
| - An array allocates storage for the data. | ||
| - A pointer just stores an address, which may point to a string literal (read-only) or to a buffer (modifiable). | ||
|
|
||
| --- | ||
|
|
||
| ## Library functions | ||
|
|
||
| In this library we have the following functions for manipulating strings: | ||
| This library provides the following functions for manipulating strings: | ||
| - `length`: get the length of a string. | ||
| - `equal`: check if two strings are the same. | ||
| - `copy`: copy characters from one string to another string. | ||
| - `subcopy`: copy a specific portion of a string, using the starting index and an ending index, to another string. | ||
| - `copy`: copy characters from one string to another. | ||
| - `subcopy`: copy a specific portion of a string, using the starting and ending index, to another string. | ||
| - `subcopy_len`: copy a specific portion of a string, using the length, to another string. | ||
| - `subcopy_index_len`: copy a specific portion of a string, using the starting index and the length, to another string. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,31 +1,26 @@ | ||
| #ifndef DEBUG | ||
| #include <stdio.h> | ||
| #endif | ||
|
|
||
| /* | ||
| * cBytes library | ||
| * Bytekit library | ||
| * Author: David Gaspar <davidgaspar.dev@gmail.com> | ||
| */ | ||
| #ifndef CBYTES_H_ | ||
| #define CBYTES_H_ | ||
| #ifndef BYTEKIT_H | ||
| #define BYTEKIT_H | ||
|
|
||
| typedef char byte_t; | ||
| typedef unsigned char ubyte_t; | ||
| typedef char *bytes_t; | ||
| typedef const char *cbytes_t; | ||
| typedef byte_t *bytes_t; | ||
| typedef const byte_t *cbytes_t; | ||
|
|
||
| #ifndef bool | ||
| #define true (ubyte_t)1 | ||
| #define false (ubyte_t)0 | ||
| #define true (byte_t)1 | ||
| #define false (byte_t)0 | ||
| #endif | ||
|
|
||
| unsigned int length(cbytes_t arg); | ||
|
|
||
| int index_of(cbytes_t target, cbytes_t fragment); | ||
| ubyte_t equal(cbytes_t bytes_1, cbytes_t bytes_2); | ||
| byte_t equal(cbytes_t bytes_1, cbytes_t bytes_2); | ||
| byte_t copy(cbytes_t src, bytes_t dst, unsigned long sizeof_dst); | ||
| byte_t subcopy(cbytes_t src, unsigned int start_index, unsigned int end_index, bytes_t dst, unsigned long sizeof_dst); | ||
| byte_t subcopy_len(cbytes_t src, unsigned int dst_length, bytes_t dst, unsigned long sizeof_dst); | ||
| byte_t subcopy_index_len(cbytes_t src, unsigned int start_index, unsigned int dst_length, bytes_t dst, unsigned long sizeof_dst); | ||
|
|
||
| #endif | ||
| #endif | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| #include <cbytes.h> | ||
| #include <bytekit.h> | ||
| #include "utils/log.c" | ||
|
|
||
| void copy_test(const char *data) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| #include <cbytes.h> | ||
| #include <bytekit.h> | ||
| #include "utils/log.c" | ||
|
|
||
| int test_copy() { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The typedef
byte_t *bytes_tcreates a redundant type alias. Sincebyte_tis already defined aschar, this is equivalent tochar *bytes_t, which could be confusing. Consider usingchar *directly or renaming to be more descriptive likebyte_array_t.