Back to index

salome-kernel  6.5.0
Functions
SALOMEDSImpl_AttributeParameter.cxx File Reference
#include "SALOMEDSImpl_AttributeParameter.hxx"
#include <stdio.h>
#include <stdlib.h>
#include <sstream>

Go to the source code of this file.

Functions

std::string convertString (const std::string &S)
std::string restoreString (const std::string &S)

Function Documentation

std::string convertString ( const std::string &  S)

Definition at line 37 of file SALOMEDSImpl_AttributeParameter.cxx.

{
  int length = S.size();
  const char *s = S.c_str();
  char *c = new char[3], *buffer = new char[length*3+1];
  buffer[length*3] = (char)0;
  for(int i = 0, pos = 0; i<length; i++, pos+=3) {
    int val = (int)s[i];
    buffer[pos] = '%';
    sprintf(c, "%.2x", val);
    buffer[pos+1] = c[0]; 
    buffer[pos+2] = c[1];
  }

  std::string RS(buffer); 
  delete c;
  delete buffer;
  return RS;
}
std::string restoreString ( const std::string &  S)

Definition at line 58 of file SALOMEDSImpl_AttributeParameter.cxx.

{
  int length = S.size();
  char *c = new char[3], *buffer = new char[length/3+1];
  buffer[length/3] = (char)0;
  const char *s = S.c_str();
  for(int i = 0, pos = 0; i<length; i+=3, pos++) {
    c[0] = s[i+1];
    c[1] = s[i+2];
    c[2] = (char)0;
    int val = strtol(c, NULL, 16);
    buffer[pos] = (char)val;
  }

  std::string RS(buffer); 
  delete c;
  delete buffer;
  return RS;
}