Convert Figma logo to code with AI

yaml logolibyaml

Canonical source repository for LibYAML

1,014
332
1,014
103

Top Related Projects

6,346

JavaScript YAML parser and dumper. Very fast.

Quick Overview

LibYAML is a C library for parsing and emitting YAML (YAML Ain't Markup Language) data. It provides a fast and efficient way to work with YAML in C applications, offering both a simple high-level interface for parsing and emitting YAML, as well as lower-level event-based parsing and emitting interfaces.

Pros

  • Fast and efficient YAML parsing and emitting in C
  • Supports both simple high-level and more complex event-based interfaces
  • Widely used and well-maintained, with regular updates and bug fixes
  • Compliant with the YAML 1.1 specification

Cons

  • Limited to C language, requiring wrappers for use in other languages
  • Documentation could be more comprehensive, especially for advanced usage
  • Lacks some features present in newer YAML specifications (e.g., YAML 1.2)
  • May require additional error handling for complex YAML structures

Code Examples

  1. Parsing a YAML file:
#include <yaml.h>
#include <stdio.h>

int main(void) {
    FILE *file = fopen("example.yaml", "r");
    yaml_parser_t parser;
    yaml_event_t event;

    yaml_parser_initialize(&parser);
    yaml_parser_set_input_file(&parser, file);

    do {
        if (!yaml_parser_parse(&parser, &event)) {
            // Handle error
            break;
        }

        // Process the event
        // ...

        yaml_event_delete(&event);
    } while (event.type != YAML_STREAM_END_EVENT);

    yaml_parser_delete(&parser);
    fclose(file);
    return 0;
}
  1. Emitting YAML:
#include <yaml.h>
#include <stdio.h>

int main(void) {
    yaml_emitter_t emitter;
    yaml_event_t event;

    yaml_emitter_initialize(&emitter);
    yaml_emitter_set_output_file(&emitter, stdout);

    yaml_stream_start_event_initialize(&event, YAML_UTF8_ENCODING);
    yaml_emitter_emit(&emitter, &event);

    yaml_document_start_event_initialize(&event, NULL, NULL, NULL, 0);
    yaml_emitter_emit(&emitter, &event);

    yaml_scalar_event_initialize(&event, NULL, (yaml_char_t *)"tag:yaml.org,2002:str",
        (yaml_char_t *)"Hello, World!", -1, 1, 0, YAML_PLAIN_SCALAR_STYLE);
    yaml_emitter_emit(&emitter, &event);

    yaml_document_end_event_initialize(&event, 0);
    yaml_emitter_emit(&emitter, &event);

    yaml_stream_end_event_initialize(&event);
    yaml_emitter_emit(&emitter, &event);

    yaml_emitter_delete(&emitter);
    return 0;
}

Getting Started

To use LibYAML in your C project:

  1. Install LibYAML on your system (e.g., sudo apt-get install libyaml-dev on Ubuntu)
  2. Include the header in your C file: #include <yaml.h>
  3. Compile your program with the LibYAML library: gcc -o program program.c -lyaml
  4. Use the LibYAML functions in your code, such as yaml_parser_initialize() for parsing or yaml_emitter_initialize() for emitting YAML

Remember to check the return values of LibYAML functions for error handling and to properly clean up resources (e.g., calling yaml_parser_delete() or yaml_emitter_delete()).

Competitor Comparisons

6,346

JavaScript YAML parser and dumper. Very fast.

Pros of js-yaml

  • Written in JavaScript, making it easily integrable with Node.js and browser-based applications
  • Supports both YAML parsing and dumping (serialization)
  • Actively maintained with frequent updates and a large community

Cons of js-yaml

  • Generally slower performance compared to C-based libyaml
  • May have larger memory footprint, especially for large YAML documents
  • Limited support for some advanced YAML features found in libyaml

Code Comparison

js-yaml:

const yaml = require('js-yaml');
const fs = require('fs');

const doc = yaml.load(fs.readFileSync('file.yml', 'utf8'));
console.log(doc);

libyaml (using a C wrapper):

#include <yaml.h>

yaml_parser_t parser;
yaml_document_t document;

yaml_parser_initialize(&parser);
yaml_parser_load(&parser, &document);
// Process the document
yaml_document_delete(&document);
yaml_parser_delete(&parser);

The code examples demonstrate the simplicity of using js-yaml in a JavaScript environment compared to the more complex C-based approach of libyaml. However, libyaml offers lower-level control and potentially better performance for certain use cases.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

LibYAML - A C library for parsing and emitting YAML.

To build and install the library, run:

$ ./configure
$ make
# make install

Required packages:

  • gcc
  • libtool
  • make

If you checked the source code from the Git repository, run

$ ./bootstrap
$ ./configure
$ make
# make install

Required packages:

  • autoconf
  • libtool
  • make

For more information, check the LibYAML homepage.

Discuss LibYAML with the maintainers in IRC #libyaml irc.freenode.net.

You may also use the YAML-Core mailing list.

Submit bug reports and feature requests to the LibYAML bug tracker.

This project was developed for Python Software Foundation as a part of Google Summer of Code under the mentorship of Clark Evans.

The LibYAML module was written by Kirill Simonov xi@resolvent.net. It is currently maintained by the YAML community.

LibYAML is released under the MIT license. See the file LICENSE for more details.