Code Monkey home page Code Monkey logo

hmon's Introduction

Hatim's Minimal Object Notation

A minimal object notation library in C!

Overview

This is a minimal object notation, mainly used for my personal projects, so keep your expectations low

Basic usage

The syntax of an object looks like this:

(username = 'John Doe', password = 'SOMEPASS123', age = 18, isBanned = false)

The C Api

Example of usage (this includes almost every function you need):

#define HMON_MAX_KEY_LEN 25 // This is 50 by default
#define HMON_MAX_VALUE_STRING 20 // 50 by default
#include <hmon.h>

int main(void) {
  // Creating an object
  HMON_Object *object = NULL;

  // Adding object properties
  hmon_object_add_string(&object, "firstName", "John");
  hmon_object_add_string(&object, "lastName", "Doe");
  hmon_object_add_int(&object, "age", 32);
  hmon_object_add_boolean(&object, "likesCoffee", true);

  // Deleting a key
  hmon_object_delete_key(&object, "lastName");

  // Printing an object
  hmon_object_print(&object);

  // Length of an object (how many key-value pairs it has)
  size_t length = hmon_object_length(&object);
  printf("Object has %zu key-value pairs\n", length);

  if (hmon_object_has_key(&object, "age")) {
    printf("Object has 'age' key\n");
  }

  // Format object into a heap allocated string
  char *format = hmon_object_format(&object);
  if (format != NULL) {
    printf("Format: %s\n", format);
    free((void*)format);
  }

  // Destroying object
  hmon_object_destroy(&object);

  // Much more in the example directory!
  return 0;
}

Output:

(firstName='John') -> (age=31) -> (likesCoffee=true) -> (X)
Object has 3 key-value pairs
Object has 'age' key
Format: (firstName='John', age=31, likesCoffee=true)

More examples in examples/

Example of usage

These are the type of personal projects I was talking about

Does this support arrays and nesting ?

No

License

MIT License.

hmon's People

Stargazers

Hatim avatar

Watchers

Hatim avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.