Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
MaJerle committed May 17, 2024
2 parents 8902a7a + 46dc5f2 commit 278848a
Show file tree
Hide file tree
Showing 28 changed files with 812 additions and 364 deletions.
4 changes: 2 additions & 2 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ AlignConsecutiveBitFields:
AlignConsecutiveDeclarations: None
AlignEscapedNewlines: Right
AlignOperands: Align
SortIncludes: false
SortIncludes: true
InsertBraces: true # Control statements must have curly brackets
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortEnumsOnASingleLine: true
AllowShortBlocksOnASingleLine: Empty
AllowShortCaseLabelsOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: true
AllowShortFunctionsOnASingleLine: All
AllowShortLambdasOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Never
Expand Down
19 changes: 19 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
Checks: "*,
-abseil-*,
-altera-*,
-android-*,
-fuchsia-*,
-google-*,
-llvm*,
-modernize-use-trailing-return-type,
-zircon-*,
-readability-else-after-return,
-readability-static-accessed-through-instance,
-readability-avoid-const-params-in-decls,
-cppcoreguidelines-non-private-member-variables-in-classes,
-misc-non-private-member-variables-in-classes,
"
WarningsAsErrors: ''
HeaderFilterRegex: ''
FormatStyle: none
18 changes: 18 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version: 2
build:
os: ubuntu-22.04
tools:
python: "3.11"

# Build documentation in the docs/ directory with Sphinx
sphinx:
configuration: docs/conf.py

# Python configuration
python:
install:
- requirements: docs/requirements.txt

formats:
- pdf
- epub
6 changes: 4 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"lwevt.h": "c",
"string.h": "c",
"lwevt_opt.h": "c",
"lwjson.h": "c"
"lwjson.h": "c",
"lwjson_opt.h": "c"
},
"esbonio.sphinx.confDir": ""
"esbonio.sphinx.confDir": "",
"C_Cpp.codeAnalysis.clangTidy.useBuildPath": true
}
7 changes: 7 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Tilen Majerle <[email protected]>
Tilen Majerle <[email protected]>
Tristen Pierson <[email protected]>
erics <[email protected]>
Eric Sidorov <[email protected]>
erics <[email protected]>
Josef Salda <[email protected]>
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

## Develop

## 1.7.0

- Add clang-tidy
- Add helper functions for sequence check in stream parsing
- Add support to discard invalid JSON stream
- Fixed some invalid JSON parsing in the streaming module

## 1.6.1

- Fix critical issue - missing correct return when waiting for first character. Should be `lwjsonSTREAMWAITFIRSTCHAR`
Expand Down
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ project(LwLibPROJECT)
if(NOT PROJECT_IS_TOP_LEVEL)
add_subdirectory(lwjson)
else()
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# Set as executable
add_executable(${PROJECT_NAME})

Expand All @@ -16,6 +18,7 @@ else()
${CMAKE_CURRENT_LIST_DIR}/examples/example_minimal.c
${CMAKE_CURRENT_LIST_DIR}/examples/example_traverse.c
${CMAKE_CURRENT_LIST_DIR}/examples/example_stream.c
${CMAKE_CURRENT_LIST_DIR}/trial_env/trial_run.c
)

# Add key include paths
Expand All @@ -28,7 +31,6 @@ else()
WIN32
_DEBUG
CONSOLE
LWJSON_DEV
)

# Compiler options
Expand All @@ -39,6 +41,7 @@ else()
)

# Add subdir with lwjson and link to project
set(LWJSON_OPTS_FILE ${CMAKE_CURRENT_LIST_DIR}/dev/lwjson_opts.h)
add_subdirectory(lwjson)
target_link_libraries(${PROJECT_NAME} lwjson)
target_link_libraries(${PROJECT_NAME} lwjson_debug)
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023 Tilen MAJERLE
Copyright (c) 2024 Tilen MAJERLE

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ First one being optimized for ultra small microcontrollers, second one being rea

## Features

* Written in ANSI C99, compatible with ``size_t`` for size data types
* Written in C (C11), compatible with ``size_t`` for size data types
* RFC 4627 and RFC 8259 compliant
* Based on static token allocation with optional application dynamic pre-allocation
* No recursion during parse operation
Expand All @@ -22,7 +22,7 @@ First one being optimized for ultra small microcontrollers, second one being rea

## Contribute

Fresh contributions are always welcome. Simple instructions to proceed::
Fresh contributions are always welcome. Simple instructions to proceed:

1. Fork Github repository
2. Follow [C style & coding rules](https://github.com/MaJerle/c-code-style) already used in the project
Expand Down
14 changes: 7 additions & 7 deletions dev/lwjson_opts.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

/*
* Copyright (c) 2023 Tilen MAJERLE
* Copyright (c) 2024 Tilen MAJERLE
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
Expand All @@ -29,18 +29,18 @@
* This file is part of LwJSON - Lightweight JSON format parser.
*
* Author: Tilen MAJERLE <[email protected]>
* Version: v1.6.1
* Version: v1.7.0
*/
#ifndef LWJSON_HDR_OPTS_H
#define LWJSON_HDR_OPTS_H
#ifndef LWJSON_OPTS_HDR_H
#define LWJSON_OPTS_HDR_H

/* Rename this file to "lwjson_opts.h" for your application */

/*
* Open "include/lwjson/lwjson_opt.h" and
* copy & replace here settings you want to change values
*/
#define LWJSON_CFG_JSON5 1
#define LWJSON_CFG_COMMENTS 1
#define LWJSON_CFG_JSON5 1
#define LWJSON_CFG_COMMENTS 1

#endif /* LWJSON_HDR_OPTS_H */
#endif /* LWJSON_OPTS_HDR_H */
11 changes: 10 additions & 1 deletion dev/main.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include "windows.h"
#include "lwjson/lwjson.h"
#include "windows.h"

/* Classic parser */
static lwjson_token_t tokens[4096];
Expand All @@ -16,6 +16,9 @@ extern void example_minimal_run(void);
extern void example_traverse_run(void);
extern void example_stream_run(void);

/* Trial stream -> for a user to try its own code... */
extern void trial_stream_run(void);

static void jsp_stream_callback(lwjson_stream_parser_t* jsp, lwjson_stream_type_t type);

int
Expand All @@ -28,10 +31,16 @@ main() {

(void)token_cnt;
#if 0
trial_stream_run();
return 0;
#endif
#if 1
test_run();
#if 1
example_minimal_run();
example_traverse_run();
example_stream_run();
#endif
return 0;
#endif

Expand Down
8 changes: 8 additions & 0 deletions docs/authors/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.. _authors:

Authors
=======

List of authors and contributors to the library

.. literalinclude:: ../../AUTHORS
20 changes: 17 additions & 3 deletions docs/get-started/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,17 @@ Add library to project
^^^^^^^^^^^^^^^^^^^^^^

At this point it is assumed that you have successfully download library, either cloned it or from releases page.
Next step is to add the library to the project, by means of source files to compiler inputs and header files in search path
Next step is to add the library to the project, by means of source files to compiler inputs and header files in search path.

*CMake* is the main supported build system. Package comes with the ``CMakeLists.txt`` and ``library.cmake`` files, both located in the ``lwjson`` directory:

* ``CMakeLists.txt``: Is a wrapper and only includes ``library.cmake`` file. It is used if target application uses ``add_subdirectory`` and then uses ``target_link_libraries`` to include the library in the project
* ``library.cmake``: It is a fully configured set of variables. User must use ``include(path/to/library.cmake)`` to include the library and must manually add files/includes to the final target

.. tip::
Open ``library.cmake`` file and manually analyze all the possible variables you can set for full functionality.

If you do not use the *CMake*, you can do the following:

* Copy ``lwjson`` folder to your project, it contains library files
* Add ``lwjson/src/include`` folder to `include path` of your toolchain. This is where `C/C++` compiler can find the files during compilation process. Usually using ``-I`` flag
Expand All @@ -70,15 +80,19 @@ Configuration file
^^^^^^^^^^^^^^^^^^

Configuration file is used to overwrite default settings defined for the essential use case.
Library comes with template config file, which can be modified according to needs.
Library comes with template config file, which can be modified according to the application needs.
and it should be copied (or simply renamed in-place) and named ``lwjson_opts.h``

.. note::
Default configuration template file location: ``lwjson/src/include/lwjson/lwjson_opts_template.h``.
File must be renamed to ``lwjson_opts.h`` first and then copied to the project directory where compiler
include paths have access to it by using ``#include "lwjson_opts.h"``.

List of configuration options are available in the :ref:`api_lwjson_opt` section.
.. tip::
If you are using *CMake* build system, define the variable ``LWJSON_OPTS_FILE`` before adding library's directory to the *CMake* project.
Variable must contain the path to the user options file. If not provided and to avoid build error, one will be generated in the build directory.

Configuration options list is available available in the :ref:`api_lwjson_opt` section.
If any option is about to be modified, it should be done in configuration file

.. literalinclude:: ../../lwjson/src/include/lwjson/lwjson_opts_template.h
Expand Down
5 changes: 3 additions & 2 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ LwJSON is a generic JSON parser library optimized for embedded systems.
Features
^^^^^^^^

* Written in ANSI C99, compatible with ``size_t`` for size data types
* Written in C (C11), compatible with ``size_t`` for size data types
* RFC 4627 and RFC 8259 compliant
* Based on static token allocation with optional application dynamic pre-allocation
* No recursion during parse operation
Expand Down Expand Up @@ -73,6 +73,7 @@ Table of contents
user-manual/index
api-reference/index
changelog/index
authors/index

.. toctree::
:maxdepth: 2
Expand All @@ -84,7 +85,7 @@ Table of contents
LwESP - ESP-AT library <https://github.com/MaJerle/lwesp>
LwEVT - Event manager <https://github.com/MaJerle/lwevt>
LwGPS - GPS NMEA parser <https://github.com/MaJerle/lwgps>
LwGSM - GSM-AT library <https://github.com/MaJerle/lwgsm>
LwCELL - Cellular modem host AT library <https://github.com/MaJerle/lwcell>
LwJSON - JSON parser <https://github.com/MaJerle/lwjson>
LwMEM - Memory manager <https://github.com/MaJerle/lwmem>
LwOW - OneWire with UART <https://github.com/MaJerle/lwow>
Expand Down
8 changes: 3 additions & 5 deletions examples/example_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@ static lwjson_stream_parser_t stream_parser;
* \param jsp: JSON stream parser object
* \param type: Event type
*/
void
static void
prv_example_callback_func(lwjson_stream_parser_t* jsp, lwjson_stream_type_t type) {
/* Get a value corresponsing to "k1" key */
if (jsp->stack_pos >= 2 /* Number of stack entries must be high */
&& jsp->stack[0].type == LWJSON_STREAM_TYPE_OBJECT /* First must be object */
&& jsp->stack[1].type == LWJSON_STREAM_TYPE_KEY /* We need key to be before */
&& strcmp(jsp->stack[1].meta.name, "k1") == 0) {
if (jsp->stack_pos >= 2 /* Number of stack entries must be high */
&& lwjson_stack_seq_2(jsp, 0, OBJECT, KEY) && strcmp(jsp->stack[1].meta.name, "k1") == 0) {
printf("Got key '%s' with value '%s'\r\n", jsp->stack[1].meta.name, jsp->data.str.buff);
}
(void)type;
Expand Down
Loading

0 comments on commit 278848a

Please sign in to comment.