29#include "fojson_utils.h"
37#define utils_debug_key "fojson"
41std::string escape_for_json(
const std::string &input) {
43 for (
size_t i = 0; i < input.size(); ++i) {
44 if (
unsigned(input[i]) <
'\x20' || input[i] ==
'\\' || input[i] ==
'"') {
45 ss <<
"\\u" << std::setfill(
'0') << std::setw(4) << std::hex << unsigned(input[i]);
61long computeConstrainedShape(libdap::Array *a, std::vector<unsigned int> *shape ){
62 BESDEBUG(utils_debug_key,
"fojson::computeConstrainedShape() - BEGIN. Array name: "<< a->name() << endl);
64 libdap::Array::Dim_iter dIt;
69 unsigned int dimSize = 1;
73 BESDEBUG(utils_debug_key,
"fojson::computeConstrainedShape() - Array has " << a->dimensions(
true) <<
" dimensions."<< endl);
75 for(dIt = a->dim_begin() ; dIt!=a->dim_end() ;dIt++){
76 BESDEBUG(utils_debug_key,
"fojson::computeConstrainedShape() - Processing dimension '" << a->dimension_name(dIt)<<
"'. (dim# "<< dimNum <<
")"<< endl);
77 start = a->dimension_start(dIt,
true);
78 stride = a->dimension_stride(dIt,
true);
79 stop = a->dimension_stop(dIt,
true);
80 BESDEBUG(utils_debug_key,
"fojson::computeConstrainedShape() - start: " << start <<
" stride: " << stride <<
" stop: "<<stop<< endl);
82 dimSize = 1 + ( (stop - start) / stride);
83 BESDEBUG(utils_debug_key,
"fojson::computeConstrainedShape() - dimSize: " << dimSize << endl);
85 (*shape)[dimNum++] = dimSize;
88 BESDEBUG(utils_debug_key,
"fojson::computeConstrainedShape() - totalSize: " << totalSize << endl);
89 BESDEBUG(utils_debug_key,
"fojson::computeConstrainedShape() - END." << endl);
99std::string backslash_escape(std::string source,
char char_to_escape){
100 std::string escaped_result = source;
101 if(source.find(char_to_escape) != string::npos ){
103 for(
size_t i=0; i< source.size() ; i++){
104 if(source[i] == char_to_escape){
105 escaped_result.insert( i + found++,
"\\");
109 return escaped_result;