Skip to content

Commit

Permalink
refs #4428 implemented the serialize_to_string() method as the counte…
Browse files Browse the repository at this point in the history
…rpart to parse_to_qore_value()
  • Loading branch information
davidnich committed Feb 9, 2022
1 parent cee853e commit 34614ac
Show file tree
Hide file tree
Showing 11 changed files with 122 additions and 23 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 2.8.12)

# NOTE: Qore should always use semantic versioning: https://semver.org/
set(VERSION_MAJOR 1)
set(VERSION_MINOR 3)
set(VERSION_MINOR 4)
set(VERSION_SUB 0)
#set(VERSION_PATCH 0)

Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# AC_PREREQ(2.59)
# NOTE: Qore should always use semantic versioning: https://semver.org/
AC_INIT([qore], [1.3.0],
AC_INIT([qore], [1.4.0],
[David Nichols <david@qore.org>],
[qore])
AM_INIT_AUTOMAKE([no-dist-gzip dist-bzip2 tar-ustar subdir-objects])
Expand Down
10 changes: 10 additions & 0 deletions doxygen/lang/900_release_notes.dox.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

@tableofcontents

@section qore_1_4_0 Qore 1.4.0

@par Release Summary
Release with minor new features; see below for more information

@subsection qore_1_4_0_new_features New Features in Qore
- <a href="../../modules/Util/html/index.html">Util</a> module
- implemented the @ref Util::serialize_to_string() "serialize_to_string()" API
(<a href="https://github.com/qorelanguage/qore/issues/4428">issue 4428</a>)

@section qore_1_3_0 Qore 1.3.0

@par Release Summary
Expand Down
15 changes: 10 additions & 5 deletions examples/test/qlib/Util/parse_to_qore_value.qtest
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,17 @@ public class ParseToQoreValueTest inherits QUnit::Test {
assertEq(("a": 1, "b": (2, 3)), parse_to_qore_value("%EVAL=('a':1, 'b': (2, 3))"));

# test support of parentheses
assertEq((1, 2, 3, ("a": "num", "b": "txt", "c": (1, 2, "three")), 5), parse_to_qore_value("1,2,3,(a=num, b=txt, c=(1, 2, \"three\")),5"));
assertEq((("a": (1, 2, 3, "num"), "b": "txt", "c": (1, 2, "three")), 5), parse_to_qore_value("(a=(1,2,3,num), b= txt , c=(1, 2, \"three\")),5"));
assertEq((1, 2, 3, ("a": "num", "b": "txt", "c": (1, 2, "three")), 5),
parse_to_qore_value("1,2,3,(a=num, b=txt, c=(1, 2, \"three\")),5"));
assertEq((("a": (1, 2, 3, "num"), "b": "txt", "c": (1, 2, "three")), 5),
parse_to_qore_value("(a=(1,2,3,num), b= txt , c=(1, 2, \"three\")),5"));
assertEq(("o": ("v": 10, "s": 11)), parse_to_qore_value("o=(v=10,s=11)"));
assertEq((("a": ("b": (("c": "x"), 2016-05-18, 3))), "x"), parse_to_qore_value("a=(b=(c=x, 2016-05-18, 3)),x"));
assertEq((("a": ("b": (("c": "x"), 2016-05-18T20:47, 3))), False), parse_to_qore_value(" a = ( b = ( c = x , 2016-05-18T20:47, 3) ) , False "));
assertEq((("a": ("b ": (("c": "x"), 2016-05-18T20:47:16.356788, 3))), True), parse_to_qore_value(" a = ( \"b \" = ( c = x , 2016-05-18T20:47:16.356788 , 3) ) , true "));
assertEq((("a": ("b": (("c": "x"), 2016-05-18, 3))), "x"),
parse_to_qore_value("a=(b=(c=x, 2016-05-18, 3)),x"));
assertEq((("a": ("b": (("c": "x"), 2016-05-18T20:47, 3))), False),
parse_to_qore_value(" a = ( b = ( c = x , 2016-05-18T20:47, 3) ) , False "));
assertEq((("a": ("b ": (("c": "x"), 2016-05-18T20:47:16.356788, 3))), True),
parse_to_qore_value(" a = ( \"b \" = ( c = x , 2016-05-18T20:47:16.356788 , 3) ) , true "));
assertEq((("a": 500), ("a": 1.234)), parse_to_qore_value("(a = 500),a=1.234"));

assertEq({"a": 1, "b": (1, 2)}, parse_to_qore_value("{a=1,b=(1,2)}"));
Expand Down
39 changes: 39 additions & 0 deletions examples/test/qlib/Util/serialize_to_string.qtest
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env qore
# -*- mode: qore; indent-tabs-mode: nil -*-

%new-style
%enable-all-warnings
%require-types
%strict-args

%requires ../../../../qlib/Util.qm
%requires ../../../../qlib/QUnit.qm

%exec-class SerializeToStringTest

public class SerializeToStringTest inherits QUnit::Test {
public {
const Values = (
True,
False,
1,
1543,
1.0,
now_us(),
(1, "two", 3.0),
{"a": 1, "b": "two"},
#M_PIn,
#P1DT5H20M415u,
);
}

constructor() : Test("SerializeToStringTest", "1.0") {
addTestCase("main", \mainTest());

set_return_value(main());
}

mainTest() {
map assertEq($1, parse_to_qore_value(serialize_to_string($1))), Values;
}
}
2 changes: 1 addition & 1 deletion qlib/DataProvider/AbstractDataProviderFactory.qc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class AbstractDataProviderFactory {
}

#! Returns static provider information as data; no objects are returned
/** @param info0 the raw info with objects describing the types
/** @param with_type_info the raw info with objects describing the types

@note the \c name and \c children attributes are not returned as they are dynamic attributes
*/
Expand Down
11 changes: 0 additions & 11 deletions qlib/DbDataProvider/DbDataProviderFactory.qc
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,6 @@
DEALINGS IN THE SOFTWARE.
*/

# minimum required Qore version
%requires qore >= 0.9.4
# assume local scope for variables, do not use "$" signs
%new-style
# require type definitions everywhere
%require-types
#! strict argument handling
%strict-args
# enable all warnings
%enable-all-warnings

#! Contains all public definitions in the DbDataProvider module
public namespace DbDataProvider {
#! The DB data provider factory
Expand Down
50 changes: 49 additions & 1 deletion qlib/Util.qm
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
%enable-all-warnings

module Util {
version = "1.6.2";
version = "1.7";
desc = "user module for generally useful routines";
author = "David Nichols <david@qore.org>";
url = "http://qore.org";
Expand Down Expand Up @@ -88,6 +88,10 @@ module Util {

@section utilrelnotes Release Notes

@subsection util_1_7 Util 1.7
- implemented the @ref Util::serialize_to_string() "serialize_to_string()" API
(<a href="https://github.com/qorelanguage/qore/issues/4428">issue 4428</a>)

@subsection util_1_6_2 Util 1.6.2
- fixed a bug in \c parse_to_qore_value() with floats and numbers with trailing zeros
(<a href="https://github.com/qorelanguage/qore/issues/4349">issue 4349</a>)
Expand Down Expand Up @@ -711,6 +715,8 @@ hash: (1 member)
@return the Qore value corresponding to the input string

@throw PARSE-ERROR cannot parse the string given

@see serialize_to_string() as a related serialization function
*/
public auto sub parse_to_qore_value(string arg) {
# see if there is aprocessing cmd
Expand Down Expand Up @@ -874,6 +880,48 @@ hash: (1 member)
return auto_cast(v);
}

#! Serializes the given value to a string that can be deserialized with parse_to_qore_value()
/** @param val the value to serialize to a string

@retun the string value reprepsenting the argument; note that this value can be passed to
@ref parse_to_qore_value() as an argument to be deserialized

@note
- This API is meant for serialization of simple types to readable strings only; for proper serialization, see
@ref Qore::Serializable
- Only \c string, \c int, \c float, \c bool, \c date (absolute), \c list, and \c hash values are supported

@throw SERIALIZATION-ERROR cannot serialize data type

@see
- parse_to_qore_value()
- @ref Qore::Serializable

@since Util 1.7
*/
public string sub serialize_to_string(auto val) {
switch (val.typeCode()) {
case NT_STRING:
return val;
case NT_INT:
return sprintf("%d", val);
case NT_FLOAT:
return sprintf("%.25g", val);
case NT_BOOLEAN:
return val ? "true" : "false";
case NT_DATE:
return val.format("IF");
case NT_LIST:
return "(" + (foldl $1 + "," + $2, (map serialize_to_string($1), val)) + ")";
case NT_HASH:
return "{" + (
foldl $1 + "," + $2,
(map sprintf("%s=%s", $1.key, serialize_to_string($1.value)), val.pairIterator())
) + "}";
}
throw "SERIALIZATION-ERROR", sprintf("cannot serialize values of type %y", val.type());
}

#! parses a URI path for a arguments and a method; where the method is the part of the path before the first \c "?" character, and arguments are after
/** @param path the URI path to parse

Expand Down
5 changes: 4 additions & 1 deletion qore.spec-fedora
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
%global user_module_dir %{_datadir}/qore-modules/

Name: qore
Version: 1.3.0
Version: 1.4.0
Release: 1%{?dist}
Summary: Multithreaded Programming Language

Expand Down Expand Up @@ -175,6 +175,9 @@ make check
%{_mandir}/man1/qore.1.*

%changelog
* Wed Feb 9 2022 David Nichols <david@qore.org> 1.4.0-1
- updated version to 1.4.0-1

* Fri Jan 28 2022 David Nichols <david@qore.org> 1.3.0-1
- updated version to 1.3.0-1
- updated libqore version to 7.4.2
Expand Down
7 changes: 6 additions & 1 deletion qore.spec-multi
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

Summary: Multithreaded Programming Language
Name: qore
Version: 1.3.0
Version: 1.4.0
Release: 1%{dist}
%if 0%{?suse_version}
License: LGPL-2.0+ or GPL-2.0+ or MIT
Expand Down Expand Up @@ -128,7 +128,9 @@ ldconfig %{_libdir}
Summary: Standard library modules
Group: System Environment/Libraries
Requires: %{libname} = %{version}-%{release}
%if ! 0%{?el7}
Recommends: %{name} = %{version}
%endif

%description stdlib
Qore is a scripting language supporting threading and embedded logic, designed
Expand Down Expand Up @@ -278,6 +280,9 @@ rm -rf $RPM_BUILD_ROOT
%endif

%changelog
* Wed Feb 9 2022 David Nichols <david@qore.org> 1.4.0
- updated version to 1.4.0

* Fri Jan 28 2022 David Nichols <david@qore.org> 1.3.0
- updated version to 1.3.0
- updated libqore version to 7.4.2
Expand Down
2 changes: 1 addition & 1 deletion qore.spec-opensuse
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

%define module_dir %{_libdir}/qore-modules
Name: qore
Version: 1.3.0
Version: 1.4.0
Release: 0
Summary: Multithreaded Programming Language
License: LGPL-2.1+ or GPL-2.0+ or MIT
Expand Down

0 comments on commit 34614ac

Please sign in to comment.