Coder Social home page Coder Social logo

hjson-cpp's People

Contributors

laktak avatar lawnighthawk avatar parona-source avatar skela avatar steffengy avatar trobro avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hjson-cpp's Issues

stringstream() performance in multi-thread

Hi, this hjson is very useful, I appreciated for your work. In my project I need to do unMarshal in multi-thread, but they are blocking, I found stringstream() in below two functions is not thread-safety, so I hope this will be helpful for those guys use hjson in multi-threads.

static bool _parseFloat(double *pNumber, const std::string &str) {
std::stringstream ss(str);

// Make sure we expect dot (not comma) as decimal point.
ss.imbue(std::locale::classic());

ss >> *pNumber;

return ss.eof() && !ss.fail() && !std::isinf(*pNumber) && !std::isnan(*pNumber);
}
static bool _parseInt(std::int64_t *pNumber, const std::string &str) {
std::stringstream ss(str);

ss >> *pNumber;

return ss.eof() && !ss.fail();
}

error: ‘int64_t’ in namespace ‘std’ does not name a type

I tried to build the library on my Arch Linux box and got this error:

$ make
[ 20%] Building CXX object src/CMakeFiles/hjson.dir/hjson_decode.cpp.o
In file included from /home/rb/src/hjson-cpp/src/hjson_decode.cpp:1:
/home/rb/src/hjson-cpp/include/hjson/hjson.h:312:8: error: ‘int64_t’ in namespace ‘std’ does not name a type
  312 |   std::int64_t to_int64() const;
      |        ^~~~~~~
make[2]: *** [src/CMakeFiles/hjson.dir/build.make:76: src/CMakeFiles/hjson.dir/hjson_decode.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:98: src/CMakeFiles/hjson.dir/all] Error 2
make: *** [Makefile:91: all] Error 2

I think the issue is a missing #include <cstdint> from the top of json.h.

missing output operator

I am missing some
std::ostream& operator << (std::ostream&, HJson::Value);
operator to be able to code in a C++ friendly way std::cout << hjv after having filled some HJson::Value hjv; (at least for debugging purposes).

A trivial (but not very efficient) implementation might be

std::ostream& operator << (std::ostream&out, HJson::Value hjv) {
  out << HJson::MarshalJson(hjv);
  return out;
}

on linux libhjson.a should go in /usr/local/lib/ by default

I am not a cmake expert (because I prefer omake to  cmake)

But on Linux, it is traditional to put libraries in /usr/local/lib per its filesystem hierarchy standard.

I don't understand why libjson.a is in /usr/local/lib/hjson; this is not a usual practice

The ugly workaround is to add a symlink:
ln -vs /usr/local/lib/hjson/libhjson.a /usr/local/lib/

Thanks

--
Basile Starynkevitch, Bourg La Reine, France
http://starynkevitch.net/Basile/index_en.html
[email protected]

give written instructions to get a debug-friendly HjonCPP library on Linux

I am not familiar at all with cmake on Linux (and honestly, I dislike it: it is hiding too much things). I much prefer omake or ninja to cmake.

Could you please add a few lines in the README.md about how to compile the HJson CPP library to get debug friendly information. On Linux with g++ or clang++ that would mean passing both -g and -O1 to the C++ compiler (it is possible, and worthwhile, to have debugging symbols and a little optimization). Of course you won't strip the library.

BTW, I also miss a shared library on Linux, that is a libhjsoncpp.so. See Drepper's paper How to write shared libraries for details, and the old Program Library HowTo

Thanks a lot.

Library loses commentary

Hello together,
if I use Hjson::Unmarshal and directly Hjson::Marshal on the output, existing commentary will be lost / deleted in resulting output. Is this intended behaviour?
In hjson-cs I'm able to preserve commentary by using LoadWsc and saving with keepWsc == true. Do I miss something or is this impossible with hjson-cpp?
Greatings,
Jan

Only dump assigned values to file

It seems like this library keeps track of assigned values during their lifecycle via the variable wasAssigned.

If it's possible to write only assigned variables to a file it would be able to distinguish between base and overwritten values. Thus, it could be possible to use Merge() to assemble it back together.

Missing unmarshaling from C++ std::string

I really miss a

 Value Unmarshal(const std::string& s) {
     return Unmarshall(s.c_str(), s.size());
}

member function in HJson::Value

It seems natural to be able to unnmarshal from C++ strings, since hjson-cpp is a C++ library

Gigantic linker error message

I might have understood something wrong, but when I tried this code

#include "hjson.h"
#include <iostream>
#include <cstdio>

int main() {
  std::string sampleText = R"(
{
  rate: 12.1
  array:
  [
    foo
    bar
  ]
}
)";

  Hjson::Value dat = Hjson::Unmarshal(sampleText.c_str());
  double lol = dat["rate"];
  std::cout << lol;
  return 0;
}

it gave me a linker error so big that it did not fit on my screen.

Issues when unmarshalling arrays containing 'null' values

Found different issues with null values in arrays - some times elements are missing and in other cases the parser bails to a non-existing syntax error. Error behaviour is kind of undeterministic, so I prepared a small test program which hopefully allows to reproduce it.

Source Code

The source code contains infos on compiler flags and architecture as well.

Order is not preserved.

First of all. thank you for making this.
hjson is vastly more fun to work with due to no "" all over.
Anyway, hjson-cpp seems to sort the hjson elements when i do
Value dat = Hjson::Unmarshal(hjsonStrInput);
std::string hjsonOut = Hjson::Marshal(dat);

I used it for an editor so it is very confusing that stuff moves around.
Is there any way to keep the actual order of the elements?
I used hjson for a templates system and the order is kinda important
as alphabetically will mess up the natural grouping.

Add it to vcpkg

Add it to vcpkg package manager and also make it as a header only library?

handing of 64 bits integers missing

It seems that it is not possible to code reliably (on 64 bits systems like Linux/x86-64) something like:

std::int64_t ii = 1000000*1000000; // don't fit in an int
Hjson::Value hval(ii);

and of course get the same value later at parsing time.

Basile Starynkevitch working on RefPerSys

failure to parse simple HJson

the bug might be mine. In https://gitlab.com/bstarynk/refpersys/
It is about http://refpersys.org/
File refpersys/rps_manifest.hjson does not parse. Here it is:

// see http://refpersys.org/
{
  format: RefPerSysFormat2019A
}
// end of file rps_manifest.hjson

is it supposed to be parsable by HjsonCPP 1.3?

I am getting an Hjson::type_mismatch exception with Illegal type for this operation.

Perhaps you could add a simple program which parses and canonicalize some HJSON file.

BTW, this is commit c59ed18 of HJson with commit 5f7532afc95772d8338876 of RefPerSys

Exception Handling in Unmarshall

When reading and parsing a hjson-file without curly brackets in the beginning, ill formatted text will not throw an exception due to ignoring it.

This behaviour is internally correct, so you will identify ill formatted files in your code correctly, but you don't pass it to the outer layer. The attached example will not print the error and silently continues.

// hjson_decode: 495
// Braces for the root object are optional
static Value _rootValue(Parser *p) {
 //[...]

  // assume we have a root object without braces
  try {
    res = _readObject(p, true);
    if (!_hasTrailing(p)) {
      return res;
    }
  } catch(syntax_error e) {} // This is problematic

  // test if we are dealing with a single JSON value instead (true/false/null/num/"")
  _resetAt(p);
  res = _readValue(p);
  if (!_hasTrailing(p)) {
    return res;
  }

  throw syntax_error(_errAt(p, "Syntax error, found trailing characters"));
}

You can test this using this file:

Global:
{
   MyGroup:
    {
        Key1: 1000		// Comment 1
		Key2: 2000		// Comment 2
		Key3:"Tests		// This line is not correct
		Key4: 1234
    }
}

My suggestion would be to rethrow the error. Why are you ignoring it?

toJson()

Hi,

It is great to have an hjson implementation in C++, thank you! I was wondering if there is any plan to implement a toJson() feature which would allow us to convert hjson content to json.

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.