Files
yab-ssg/tests/main.c
2025-11-28 19:38:18 -05:00

46 lines
1.1 KiB
C

#include "../include/lenstr.h"
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
int main(void)
{
// C-style to string
string a;
a.chars = "Manual transformation of C-style to String";
a.length = strlen(a.chars);
PrintStr(a);
// Automatic c-style to string
string b = CStyleToLengthString_Assign("Function transformation of C-style to String");
PrintStr(b);
// String assigning (shallow copy) and copying (deep copy)
char xx[] = "String Assign Copy";
char yy[] = "String Deep Copy";
string x = CStyleToLengthString_Assign(xx);
string y = CStyleToLengthString_Assign(yy);
string c = x;
PrintStr(c);
string d = StringCopy(y);
PrintStr(d);
x.chars[3] = '!';
y.chars[3] = '!';
PrintStr(c);
PrintStr(d);
// Manual string slicing
string e;
e.chars = &a.chars[7];
e.length = 14;
PrintStr(e);
// Automatic string slicing (by length or by index range)
string f = StringSlice_Length(a, 7, 14);
string g = StringSlice_Index(a, 7, 21);
PrintStr(f);
PrintStr(g);
return 0;
}