Exemplo n.º 1
0
bool utf8ToLatin1(char* intext, std::string& outtext)
{
	outtext = "";
	if(!intext)
		return false;

	int32_t inlen = strlen(intext);
	if(!inlen)
		return false;

	int32_t outlen = inlen * 2;
	uint8_t* outbuf = new uint8_t[outlen];

	int32_t res = UTF8Toisolat1(outbuf, &outlen, (uint8_t*)intext, &inlen);
	if(res < 0)
	{
		delete[] outbuf;
		return false;
	}

	outbuf[outlen] = '\0';
	outtext = (char*)outbuf;

	delete[] outbuf;
	return true;
}
Exemplo n.º 2
0
bool utf8ToLatin1(char* intext, std::string& outtext)
{
  outtext = "";

  if(intext == NULL){
    return false;
  }

  size_t inlen  = strlen(intext);
  if(inlen == 0){
    return false;
  }

  size_t outlen = inlen*2;
  unsigned char* outbuf = new unsigned char[outlen];
  // The casts to int* are safe according to the documentation
  // Unless inlen is negative, outlen will never be
  int res = UTF8Toisolat1(outbuf, (int*)&outlen, (unsigned char*)intext, (int*)&inlen);
  if(res < 0){
    delete[] outbuf;
    return false;
  }

  outtext = std::string((char*)outbuf, outlen);
  delete[] outbuf;
  return true;
}
Exemplo n.º 3
0
//--------------------------------------------------
// Helper function that converts UTF8 to ISO Latin1
// utf8in - input data in UTF8
// asciiout - output buffer for ISO Latin1 text
// outlen - output buffer length
// returns output buffer
//--------------------------------------------------
EXP_OPTION char* utf82ascii(const char* utf8in, char* asciiout, int* outlen)
{
    int inlen = strlen(utf8in);
    memset(asciiout, 0, *outlen);
    UTF8Toisolat1((unsigned char*)asciiout, outlen, (const unsigned char*)utf8in, &inlen);
    return asciiout;
}
Exemplo n.º 4
0
bool utf8ToLatin1(const char* intext, std::string& outtext)
{
    outtext = "";

    if (intext == NULL) {
        return false;
    }

    int32_t inlen = strlen(intext);
    if (inlen == 0) {
        return false;
    }

    int32_t outlen = (inlen << 1) + 1;
    unsigned char* outbuf = new uint8_t[outlen];

    int32_t res = UTF8Toisolat1(outbuf, &outlen, (const unsigned char*)intext, &inlen);
    if (res < 0) {
        delete[] outbuf;
        return false;
    }

    outtext = std::string((char*)outbuf, outlen);
    delete[] outbuf;
    return true;
}
Exemplo n.º 5
0
char* fromUTF8 (const xmlChar* str, int len)
{
	int out_size = len+1;
	int out_len = out_size;
	int in_len = len;
	char* out = calloc (out_size, 1);

	if (UTF8Toisolat1 (BAD_CAST out, &out_len, str, &in_len) < 0)
	{
		// Conversion error
		free (out);
		return NULL;
	}

	out[out_len] = '\0';

	return out;
}
Exemplo n.º 6
0
/*!
  @param node - the XML DOM node which contains the specified property
  @param propertyName - the name of the desired property
  @return the string value of the property with the specified name
  @return "" is returned if the property is not found
*/
string GetStringValue(xmlNodePtr node, const char* propertyName)
{
  xmlChar *propertyValue;
  int maxLen, retcode;
  string value="";
  char* buf;

  propertyValue = xmlGetProp(node, (const xmlChar *)propertyName);
  if ( propertyValue )
  {
    maxLen = strlen((char *)propertyValue)+1;
    buf = new char[maxLen];
    retcode = UTF8Toisolat1((unsigned char*)buf,&maxLen,(unsigned char*)propertyValue,&maxLen);
    if ( retcode >= 0 )
      value = buf;
    xmlFree(propertyValue);
    delete[] buf;
  }
  return value;
}
Exemplo n.º 7
0
//----------------------------------------------------------------------------
// Returns an string param if found. Else a default value
//----------------------------------------------------------------------------
std::string CXMLTreeNode::GetPszISOProperty (const char* _pszKey, const char* _pszDefault, bool warningDefault) const
{
  std::string szRet = (char*)_pszDefault;
  
  xmlChar* value = GetProperty(_pszKey);

  if (value)
  {
    unsigned char* in = (unsigned char*)value;
    int inlen = (int)strlen((const char*)in);
    int outlen = inlen*4;
    unsigned char* out = (unsigned char*)calloc(1,outlen);
    UTF8Toisolat1(out, &outlen, in, &inlen);
    szRet = (char*)out;
    free(out);
  }
	else if(warningDefault)
	{
		LOGGER->AddNewLog(ELL_WARNING, "CXMLTreeNode::GetPszISOProperty se ha utilizado el valor por defecto:%s para el tag <%s>",_pszDefault, _pszKey);
	}

  return szRet;
}
Exemplo n.º 8
0
int LireDictionnaireCMC(char *fichierXML)
{
int i, j, k;
 
 char buf[BUFSIZ];
 char *home;
 char dtdfile[256];
 int done;
 int inlen, outlen;
 unsigned char *inbuffer,*outbuffer;
 
 extern int xmlDoValidityCheckingDefaultValue;


xmlDocPtr    doc;
xmlNsPtr     ns;
xmlNodePtr   cur;
MetvarPtr    Metvar;
xmlDtdPtr    dtd ;
xmlValidCtxt ctxt;
FILE *fh;

LIBXML_TEST_VERSION xmlKeepBlanksDefault(0);

/*
 * build an XML tree from the file;
 */
doc = xmlParseFile(fichierXML);
if (doc == NULL) return(1);

/* -----------------------------------------  */
/*  Check the document is of the right kind   */
/* ------------------------------------------ */

 inbuffer=(unsigned char *) malloc(256*sizeof(unsigned char)); 
 outbuffer=(unsigned char *) malloc(256*sizeof(unsigned char)); 

cur = xmlDocGetRootElement(doc);
if (cur == NULL ) 
{
 fprintf(stderr,"empty document\n");
 xmlFreeDoc(doc);
 return(1);
}
 
 printf("root:%s\n",cur->name);
 
 /* ---------------------- */
 /*  Parse the DTD!   */
 /* ---------------------- */
 
 home = (char *) getenv ("AFSISIO");
 strcpy(dtdfile, home);
 strcat(dtdfile, "/datafiles/constants/dict.dtd");
 dtd = xmlParseDTD(NULL,dtdfile); 
 if (! dtd ) 
   { 
   printf("Error Parsing DTD\n");
   return (1);
   }
 else
   {
   printf ("dtd->name:%s\n",dtd->name);  
   }

 /* ----------------------------------------------------------- */
 /*   Set up xmlValidCtxt for error reporting when validating   */
 /* ----------------------------------------------------------- */
 
 ctxt.userData = stderr; 
 ctxt.error    = (xmlValidityErrorFunc) fprintf;   /* register error function */ 
 ctxt.warning  = (xmlValidityWarningFunc) fprintf; /* register warning function */ 
 
 
 if ( xmlValidateDtd(&ctxt,doc,dtd) )
   {
   printf("=========Validation Ok!============\n");
   }
 else 
   {
   printf("========Validation error!===========\n");
   return (1);
   }
 
 
 /*
  * Now, walk the tree.
  */
 
 
 cur = cur->children; 
 while (cur != NULL) 
   {
   Metvar = parseMetvar(doc, ns, cur);  	   
   cur = cur->next;
   }

 for (i=0; i < nbChampsDict; i++)
   {
   printf("*--------------------------------------------------------------\n");
   strcpy(inbuffer, infoChamps[i].identifVar[FRANCAIS]);
   inlen = xmlUTF8Strsize(inbuffer, 256);
   outlen=256;
   UTF8Toisolat1(outbuffer,&outlen,inbuffer ,&inlen);
   outbuffer[outlen]='\0';
   strcpy(infoChamps[i].identifVar[FRANCAIS], outbuffer);
   printf("Champ %03d de %03d\n", i, nbChampsDict);
   printf("nomvar: %s\n", infoChamps[i].nomVar);
   printf("\tdesc fr:%s\n", infoChamps[i].identifVar[FRANCAIS]);
   printf("\tdesc en:%s\n", infoChamps[i].identifVar[ENGLISH]);
   printf("\tunites:%s\n",  infoChamps[i].unitesVar);
   
   }
 
 xmlFreeDtd(dtd);
 xmlFreeDoc(doc);
 return(0);
 
}