Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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)

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.