Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/synacktraa/pylib
This is a C library which provides python like data reading and handling functions. (WIP)
https://github.com/synacktraa/pylib
c data library python
Last synced: about 1 month ago
JSON representation
This is a C library which provides python like data reading and handling functions. (WIP)
- Host: GitHub
- URL: https://github.com/synacktraa/pylib
- Owner: synacktraa
- License: mit
- Created: 2022-06-25T17:29:21.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2023-09-22T07:54:23.000Z (over 1 year ago)
- Last Synced: 2023-09-22T21:30:44.528Z (over 1 year ago)
- Topics: c, data, library, python
- Language: C
- Homepage:
- Size: 25.4 KB
- Stars: 7
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: License
Awesome Lists containing this project
README
# Safelib
> This is a C library which provides safe data reading and handling functions.
---
## Usage### Replace
```c
#include#include "./src/pylib.h"
int main(void) {
char* str = "C language is a general-purpose programming language";
puts(replace(str, "language", "LANG"));
return 0;
}
// Output: C LANG is a general-purpose programming LANG```
### Split
```c
#include#include "./src/pylib.h"
void display(size_t cnt, char** list) {
printf("{");
for(size_t i = 0; i < cnt; i++) {
printf(" \"%s\",", list[i]);
}
printf("\b }\n");
}int main(void) {
char* str = "C language is a general-purpose programming language";
cache_t* instance = split(str, "language");
display(instance->count, instance->vector);
return 0;
}// Output: { "C ", " is a general-purpose programming ", "" }
```### Join
```c
#include#include "./src/pylib.h"
int main(void) {
char* list[3] = {"C ", " is a general-purpose programming ", ""};
puts(join(list, 3, "language"));
return 0;
}// Output: C language is a general-purpose programming language
```### Readline
```c
#include#include "./src/pylib.h"
int main(void) {
FILE* in = fopen("Makefile", "r");
puts(readline(in));
fclose(in);
return 0;
}```
### Readlines
```c
#include#include "./src/pylib.h"
void display(size_t cnt, char** list) {
for(size_t i = 0; i < cnt; i++) {
printf("%s", list[i]);
}
}int main(void) {
FILE* in = fopen("Makefile", "r");
cache_t* instance = readlines(in, 1024);
display(instance->count, instance->vector);
fclose(in);
return 0;
}
```### Read
```c
#include#include "./src/pylib.h"
int main(void) {
FILE* in = fopen("Makefile", "r");
FILE* ptr = fopen("License", "r");
// if 2nd arg is -1, read function reads the whole file
puts(read(in, -1));
puts(read(ptr, 20)); // reads 20 bytes
fclose(in);
fclose(ptr);
return 0;
}```
### Input
```c
#include#include "./src/pylib.h"
int main(void) {
char* message = input("Prompt: ");
puts(message);
return 0;
}
```### Title
```c
#include
#include "./src/safe.h"int main(void) {
char str1[] = "C is a general-purpose language, 123";
printf("%s\n",title(str1));
return 0;
}```
### Capitalize
```c
#include
#include "./src/safe.h"int main(void){
char str1[] = "c IS A genERAL-PurPosE LanGuage"
printf("%s\n", title(str1));
return 0;
}---
## **TODO**- make this library into shared library
---
## **License**### MIT
Copyright for portions of project [safelib](https://github.com/SynAcktraa/safelib) are held by [Github Account [SynAcktraa](https://github.com/SynAcktraa) Owner, 2022] as part of project [safelib](https://github.com/SynAcktraa/safelib)
All other copyright for project [safelib](https://github.com/SynAcktraa/safelib) are held by [Github Account [SynAcktraa](https://github.com/SynAcktraa) Owner, 2022].
Check the [LICENSE](LICENSE) for more details.