29#include "focovjson_utils.h"
37#define utils_debug_key "focovjson"
41void removeSubstring(std::string& str,
const std::string subStr) {
42 int n = subStr.size();
44 for (
unsigned int i = str.find(subStr); i < str.size(); i = str.find(subStr))
48long computeConstrainedShape(libdap::Array *a, std::vector<unsigned int> *shape ) {
49 BESDEBUG(utils_debug_key,
"focovjson::computeConstrainedShape() - BEGIN. Array name: "<< a->name() << endl);
51 libdap::Array::Dim_iter dIt;
56 unsigned int dimSize = 1;
60 BESDEBUG(utils_debug_key,
"focovjson::computeConstrainedShape() - Array has " << a->dimensions(
true) <<
" dimensions."<< endl);
62 for(dIt = a->dim_begin() ; dIt!=a->dim_end() ;dIt++){
63 BESDEBUG(utils_debug_key,
"focovjson::computeConstrainedShape() - Processing dimension '" << a->dimension_name(dIt)<<
"'. (dim# "<< dimNum <<
")"<< endl);
64 start = a->dimension_start(dIt,
true);
65 stride = a->dimension_stride(dIt,
true);
66 stop = a->dimension_stop(dIt,
true);
67 BESDEBUG(utils_debug_key,
"focovjson::computeConstrainedShape() - start: " << start <<
" stride: " << stride <<
" stop: "<<stop<< endl);
69 dimSize = 1 + ( (stop - start) / stride);
70 BESDEBUG(utils_debug_key,
"focovjson::computeConstrainedShape() - dimSize: " << dimSize << endl);
72 (*shape)[dimNum++] = dimSize;
75 BESDEBUG(utils_debug_key,
"focovjson::computeConstrainedShape() - totalSize: " << totalSize << endl);
76 BESDEBUG(utils_debug_key,
"focovjson::computeConstrainedShape() - END." << endl);
81string escape_for_covjson(
const std::string &input) {
83 for (
size_t i = 0; i < input.size(); ++i) {
84 if (
unsigned(input[i]) <
'\x20' || input[i] ==
'\\' || input[i] ==
'"') {
85 ss <<
"\\u" << std::setfill(
'0') << std::setw(4) << std::hex << unsigned(input[i]);
94std::string backslash_escape(std::string source,
char char_to_escape) {
95 std::string escaped_result = source;
96 if(source.find(char_to_escape) != string::npos ){
98 for(
size_t i=0; i< source.size() ; i++){
99 if(source[i] == char_to_escape){
100 escaped_result.insert( i + found++,
"\\");
104 return escaped_result;