clsUtil.cpp 20.3 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841
#include "clsUtil.h"
#include<stdlib.h>
#include"DataCollection.h"
#include"clsCrSurf.h"
#include"Renderer.h"
#include"clsStruct.h"
#include"SimpleMarkerSymbol.h"
#include"SimpleLabelRenderer.h"
#include"SimpleLineSymbol.h"
#include"SimplePolygonSymbol.h"
#include"iconv.h"
#include"clsMalloc.h"
#include"clsRect.h"
#define _USE_MATH_DEFINES
#include<math.h>
//#include <io.h>
#include <iostream>

#include <vector>
#include <stdarg.h>
#include <errno.h>
#include <sys/time.h>
#include <unistd.h>

namespace DmapCore_30
{

	clsUtil::clsUtil()
	{
	}


	clsUtil::~clsUtil()
	{
	}


	unsigned int clsUtil::RandomColor()
	{
		int r = 10 + rand() % 200;
		int g = 10 + rand() % 200;
		int b = 10 + rand() % 200;
		int a = 255;
		//int a = 110 + rand() % 100;
		//unsigned int color = (((int)(r * 255)) << 16) + (((int)(g * 255)) << 8) + (int)(b * 255) + 0xff000000;
		//unsigned int color = (((int)(r * 255)) << 16) + (((int)(g * 255)) << 8) + (int)(b * 255) + (((int)(a*255)) << 24);
		unsigned int color = (r << 16) + (g << 8) + b + (a << 24);
		return color;
	}

	bool clsUtil::Exchange4(unsigned char * here)
	{
		unsigned char temp;
		for (int i = 0; i < 2; i++)
		{
			temp = here[i];
			here[i] = here[3 - i];
			here[3 - i] = temp;
		}
		return true;
	}

	bool clsUtil::Exchange8(unsigned char * here)
	{
		unsigned char temp;
		for (int i = 0; i < 4; i++)
		{
			temp = here[i];
			here[i] = here[7 - i];
			here[7 - i] = temp;
		}
		return true;
	}

	bool clsUtil::ToCairoColor(unsigned int Color, double& r, double& g, double& b)
	{
		r = ((double)(((unsigned char *)(&Color))[2])) / 255.0;
		g = ((double)(((unsigned char *)(&Color))[1])) / 255.0;
		b = ((double)(((unsigned char *)(&Color))[0])) / 255.0;
		r += 0.001;
		g += 0.001;
		b += 0.001;
		return true;
	}
	bool clsUtil::ToCairoColor(unsigned int Color, double &r, double & g, double& b, double&a)
	{
		a = ((double)(((unsigned char *)(&Color))[3])) / 255.0;
		r = ((double)(((unsigned char *)(&Color))[2])) / 255.0;
		g = ((double)(((unsigned char *)(&Color))[1])) / 255.0;
		b = ((double)(((unsigned char *)(&Color))[0])) / 255.0;
		a += 0.001; r += 0.001; g += 0.001; b += 0.001;                 //这个做法保证令小数转回整数再取整时能不因为double的误差而小1
		return true;
	}

	int clsUtil::Hex2int(char c)
	{
		if ((c >= 'A') && (c <= 'Z'))
		{
			return c - 'A' + 10;
		}
		else if ((c >= 'a') && (c <= 'z'))
		{
			return c - 'a' + 10;
		}
		else if ((c >= '0') && (c <= '9'))
		{
			return c - '0';
		}
		return c;
	}

	bool clsUtil::ToCairoColor(string color, double &r, double & g, double& b, double&a)
	{
		if(color.at(0) == '#' && ( color.size()== 7 || color.size()== 9 ))
		{
			int index = 1;
			if(color.size()== 9)
			{a = Hex2int(color.at(index)* 16 + Hex2int(color.at(index+1))) / 255.0; index += 2;}
		
			r = Hex2int(color.at(index)* 16 + Hex2int(color.at(index+1))) / 255.0; index += 2;
			g = Hex2int(color.at(index)* 16 + Hex2int(color.at(index+1))) / 255.0; index += 2;
			b = Hex2int(color.at(index)* 16 + Hex2int(color.at(index+1))) / 255.0; index += 2;
			return true;
		}
		return false;
	}

	bool clsUtil::ReadHead(unsigned char* & here, int& not_big1, int & shapetype)
	{
		not_big1 = here[0];
		here++;                                                    //取not_big 
		if (!not_big1)
			clsUtil::Exchange4(here);
		shapetype = ((int*)here)[0];
		here += 4;                                                  //取shapetype    
		if (shapetype > 1000)
		{
			shapetype %= 16 * 16;
			here += 4;
		}
		return true;
	}

	int clsUtil::ReadInt(unsigned char*& here, int  not_big1)
	{
		clsMalloc clsM(4);
		unsigned char* mem = (unsigned char*)clsM.mem;
		memcpy(mem, here, 4);
		if (!not_big1)
			clsUtil::Exchange4(mem);
		int num = ((int*)mem)[0];
		here += 4;
		return num;
	}



	int clsUtil::ReadByte(unsigned char*& here)
	{
		if(strcmp((char *)here, "") ==0){
			return 0;
		}
		int num = ((char*)here)[0];
		here++;
		return num;
	}

	

	double clsUtil::ReadDouble(unsigned char*& here, int not_big)
	{
		clsMalloc clsM(8);
		unsigned char* mem = (unsigned char*)clsM.mem;
		memcpy(mem, here, 8);
		if (!not_big)
			clsUtil::Exchange8(mem);
		double num = ((double*)mem)[0];
		here += 8;
		return num;
	}

	char * clsUtil::ConvertEnc(const char *encFrom,const char *encTo, const char * in, char *bufout, size_t lenout)
	{
		char  *sin, *sout;
		int  lenin, ret;
		iconv_t c_pt;

		if ((c_pt = iconv_open(encTo, encFrom)) == (iconv_t)-1)     { return NULL; }
		iconv(c_pt, NULL, NULL, NULL, NULL);
		lenin = strlen(in) + 1;
		sin = (char *)in;
		sout = bufout;
		ret = iconv(c_pt, (char **)&sin, (size_t *)&lenin, &sout, (size_t *)&lenout);
		if (ret == -1)
		{
			return NULL;
		}
		iconv_close(c_pt);
		return bufout;
	}

	bool  clsUtil::ConvertEncUTF8_GB18030(const char *from, clsMalloc &m)
	{
		int len = strlen(from);
		char* sz = (char*)malloc(len + 1);
		m.mem = sz;
		//strcpy(sz, from); return true;
		clsUtil::ConvertEnc("UTF-8", "GB18030", from, m.mem, len + 1);

		return true;
	}

	bool  clsUtil::ConvertEncGB18030_UTF8(const char* from, clsMalloc &m)
	{
		int len = strlen(from);
		char* sz = (char*)malloc(6 * len + 100);
		m.mem = sz;

		clsUtil::ConvertEnc("GB18030", "UTF-8", from, m.mem, 6 * len + 100);

		return true;

	}

	bool clsUtil::DoSetLineType(int LineType, cairo_t* cr)
	{
		switch (LineType)
		{
		case dmapLineTypeSolid:
		{
								  double dashes1[] = { 10, 0 };
								  int ndash1 = sizeof (dashes1) / sizeof(dashes1[0]);
								  double offset1 = 0;
								  cairo_set_dash(cr, dashes1, ndash1, offset1);
								  break;
		}
		case (dmapLineTypeDash) :
		{
									double dashes1[] = { 50, 10 };
									int ndash1 = sizeof (dashes1) / sizeof(dashes1[0]);
									double offset1 = 0;
									cairo_set_dash(cr, dashes1, ndash1, offset1);
									break;
		}
		case (dmapLineTypeDot) :
		{
								   double dashes2[] = { 10, 10 };
								   int ndash2 = sizeof (dashes2) / sizeof(dashes2[0]);
								   double offset2 = 0;
								   cairo_set_dash(cr, dashes2, ndash2, offset2);
								   break;
		}
		case (dmapLineTypeDashDot) :
		{
									   double dashes3[] = { 50, 10, 10, 10 };
									   int ndash3 = sizeof (dashes3) / sizeof(dashes3[0]);
									   double offset3 = 0;
									   cairo_set_dash(cr, dashes3, ndash3, offset3);
									   break;
		}

		case (dmapLineTypeDashDotDot) :
		{
										  double dashes4[] = { 50, 10, 10, 10, 10, 10 };
										  int ndash4 = sizeof (dashes4) / sizeof(dashes4[0]);
										  double offset4 = 0;
										  cairo_set_dash(cr, dashes4, ndash4, offset4);
										  break;
		}

		default: //什么也不做, 直接画直线
			break;
		}
		return true;
	}

	bool clsUtil::DoSetAntialias(int iAntialias, cairo_t* cr)
	{
		//CAIRO_ANTIALIAS_DEFAULT,

    /* method */
   // CAIRO_ANTIALIAS_NONE,
   // CAIRO_ANTIALIAS_GRAY,
   // CAIRO_ANTIALIAS_SUBPIXEL,

    /* hints */
    //CAIRO_ANTIALIAS_FAST,
   // CAIRO_ANTIALIAS_GOOD,
  //  CAIRO_ANTIALIAS_BEST
	   cairo_set_antialias(cr,CAIRO_ANTIALIAS_FAST);
		return true;
		switch (iAntialias)
		{
		case dmapAntialiasingDefault:cairo_set_antialias(cr, CAIRO_ANTIALIAS_DEFAULT); break;
		case dmapAntialiasingNone:cairo_set_antialias(cr, CAIRO_ANTIALIAS_NONE); break;
		case dmapAntialiasingGray:cairo_set_antialias(cr, CAIRO_ANTIALIAS_GRAY); break;
		case dmapAntialiasingSubpixel:cairo_set_antialias(cr, CAIRO_ANTIALIAS_SUBPIXEL); break;
		case dmapAntialiasingTrue:cairo_set_antialias(cr, CAIRO_ANTIALIAS_DEFAULT); break;
		case dmapAntialiasingFalse:cairo_set_antialias(cr, CAIRO_ANTIALIAS_NONE); break;
		case dmapAntialiasingBest:cairo_set_antialias(cr, CAIRO_ANTIALIAS_BEST); break;
		default:
			/*
			还有一些枚举没用上
			*/
			break;
		}
		return true;
	}


	bool clsUtil::DrawStruct(clsCrSurf* pClsCS, DataCollection* data, int index, Renderer* pSimpleRenderer)
	{
		int renType = pSimpleRenderer->RendererType();
		int structType = data->m_iStructType;
		void * pStruct = data->m_pData;
		vector<vector<string>>* p_VVAllF = &(data->m_vAllField);
		vector<string>* p_V = &(data->m_vFieldName);

		switch (structType)
		{
		case clsStruct::Struct_Point:
		{
										clsStruct::POINT* pPoint = ((clsStruct::POINT*)(pStruct)) + index;
										if (renType == dmapSimpleMarkerSymbol)
										{
											SimpleMarkerSymbol* sms = (SimpleMarkerSymbol*)pSimpleRenderer;
											sms->DrawPOINT(pClsCS, pPoint);
										}
										else if (renType == dmapSimpleLabelRenderer)
										{
											SimpleLabelRenderer* slr = (SimpleLabelRenderer*)pSimpleRenderer;
										}
										else
											return false;//安全中断
										break;
		}
		case clsStruct::Struct_Line:
		{
									   clsStruct::LINE* pLine = ((clsStruct::LINE*)(pStruct)) + index;
									   if (renType == dmapSimpleMarkerSymbol)
									   {
										   SimpleMarkerSymbol* sms = (SimpleMarkerSymbol*)pSimpleRenderer;
										   sms->DrawMPOINT(pClsCS, pLine);
									   }
									   else if (renType == dmapSimpleLineSymbol)
									   {
										   SimpleLineSymbol* sls = (SimpleLineSymbol*)pSimpleRenderer;
										   sls->DrawLINESimple(pClsCS, pLine); //这里要传 dc 的宽和高
									   }
									   else if (renType == dmapSimplePolygonSymbol)
									   {
										   SimplePolygonSymbol* sps = (SimplePolygonSymbol*)pSimpleRenderer;
										   sps->DrawRING(pClsCS, pLine);
									   }
									   break;
		}
		case clsStruct::Struct_MLine:
		{
										clsStruct::MLINE* pMLine = ((clsStruct::MLINE*)(pStruct)) + index;
										if (renType == dmapSimpleLineSymbol)
										{
											SimpleLineSymbol * sls = (SimpleLineSymbol*)pSimpleRenderer;
											sls->DrawMLINESimple(pClsCS, pMLine);
										}
										else if (renType == dmapSimpleLabelRenderer)
										{
											;
										}
										else
											return false;//安全中断
										break;
		}
		case clsStruct::Struct_Polygon:
		{
										  clsStruct::POLYGON* pMPolygon = ((clsStruct::POLYGON*)(pStruct)) + index;
										  if (renType == dmapSimplePolygonSymbol)
										  {

										  }
										  else return false; // 安全中断
										  break;
		}
		case clsStruct::Struct_MPolygon:
		{
										   clsStruct::MPOLYGON* pMPolygon = ((clsStruct::MPOLYGON*)(pStruct)) + index;
										   if (renType == dmapSimplePolygonSymbol)
										   {
											   SimplePolygonSymbol* sps = (SimplePolygonSymbol*)pSimpleRenderer;
											   sps->DrawMPOLYGON(pClsCS, pMPolygon);
										   }
										   else if (renType == dmapSimpleLabelRenderer)
										   {
											   ;
										   }
										   else
											   return false;//安全中断
										   break;
		}
		default:
			break;
		}
		return true;
	}

	bool clsUtil::ZoomFunction(Rect* extent_from, Rect* extent_to, double& r, double & x_dis, double& y_dis)
	{
		extent_from->Normal(); extent_to->Normal();
		double w_from = extent_from->m_dRight - extent_from->m_dLeft;
		double w_to = extent_to->m_dRight - extent_to->m_dLeft;
		double h_from = extent_from->m_dTop - extent_from->m_dBottom;
		double h_to = extent_to->m_dTop - extent_to->m_dBottom;

		double r1 = w_to / w_from;
		double r2 = h_to / h_from;
		r = r1 < r2 ? r1 : r2;

		x_dis = (extent_to->m_dLeft + extent_to->m_dRight) / 2 - r*(extent_from->m_dLeft + extent_from->m_dRight) / 2;
		y_dis = (extent_to->m_dTop + extent_to->m_dBottom) / 2 - r*(extent_from->m_dTop + extent_from->m_dBottom) / 2;

		return true;
	}

	bool clsUtil::PointInRect(double x, double y, double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
	{
		//(x1,y1)和(x2,y2)组成一条直线,另外两点组成一条直线
		double k1, b1, k2, b2;
		k1 = (y2 - y1) / (x2 - x1);
		b1 = y1 - k1*x1;
		k2 = (y4 - y3) / (x4 - x3);
		b2 = y3 - k2*x3;

		//判断该点是否在两条直线之间
		bool bInLines = clsUtil::PointInLines(x, y, k1, b1, k2, b2);
		if (!bInLines)
			return false;

		//(x1,y1)和(x4,y4) 组成一条直线,另外亮点组成一条直线
		k1 = (y1 - y4) / (x1 - x4);
		b1 = y1 - k1*x1;
		k2 = (y3 - y2) / (x3 - x2);
		b2 = y2 - k2*x2;
		//判断该店是否在两条直线之间
		bInLines = clsUtil::PointInLines(x, y, k1, b1, k2, b2);
		if (!bInLines)
			return false;
		return true;
	}
	bool clsUtil::PointInLines(double x, double y, double k1, double b1, double k2, double b2)
	{
		double y1 = k1*x + b1;
		double y2 = k2* x + b2;
		if ((y >= y1) && (y <= y2))
			return true;
		if ((y <= y1) && (y >= y2))
			return true;

		return false;

	}

	double clsUtil::StandardizationAngle(double dAngle)
	{
		while (dAngle > 2 * M_PI)
			dAngle -= 2 * M_PI;
		while (dAngle < 0)
			dAngle += 2 * M_PI;
		return dAngle;
	}

	/*
	此两个函数只处理 被双引号完全包含的字符串
	*/
	string clsUtil::TryAddDoubleQuotation(string s)
	{
		//双引号开头的不加
		if ((s.c_str()[0] == '"'))
			return s;
		string ss = "\"" + s + "\"";
		return ss;
	}
	string clsUtil::TryDeleteDoubleQuotation(string s)
	{
		//不是双引号开头不去双引号
		if ((s.c_str()[0]) != '"')
			return s;
		char ss[500]; memset(ss, 0, 500);
		const char* s_ = s.c_str();
		int len = strlen(s_);

		memcpy(ss, s_ + 1, len - 2);

		return ss;
	}

	void clsUtil::GetFiles(string path, string exd, vector<string> & files)
	{
		/************************************************************************/
		/*  获取文件夹下所有文件名
		输入:
		path	:	文件夹路径
		exd		:   所要获取的文件名后缀,如jpg、png等;如果希望获取所有
		文件名, exd = ""
		输出:
		files	:	获取的文件名列表
		*/
		/************************************************************************/


/*
		//文件句柄
		long   hFile = 0;
		//文件信息
		struct _finddata_t fileinfo;
		string pathName, exdName;

		if (0 != strcmp(exd.c_str(), ""))
		{
			exdName = "\\*." + exd;
		}
		else
		{
			exdName = "\\*";
		}

		if ((hFile = _findfirst(pathName.assign(path).append(exdName).c_str(), &fileinfo)) != -1)
		{
			do
			{
				//如果是文件夹中仍有文件夹,迭代之
				//如果不是,加入列表
				if ((fileinfo.attrib &  _A_SUBDIR))
				{
					if (strcmp(fileinfo.name, ".") != 0 && strcmp(fileinfo.name, "..") != 0)
						clsUtil::GetFiles(pathName.assign(path).append("\\").append(fileinfo.name), exd, files);
				}
				else
				{
					if (strcmp(fileinfo.name, ".") != 0 && strcmp(fileinfo.name, "..") != 0)
						files.push_back(pathName.assign(path).append("\\").append(fileinfo.name));
				}
			} while (_findnext(hFile, &fileinfo) == 0);
			_findclose(hFile);
		}*/
	}

	int clsUtil::ParseStringTok(char * sz, char  toK, char ** szPtr, int maxPtr)
	{
		if (sz == 0)
		{
			return 0;
		}
		int nowCount = 0;
		int i = 0;
		szPtr[nowCount] = sz;
		nowCount++;
		if (nowCount >= maxPtr)return nowCount;

		for (;; i++)
		{
			char c = sz[i];
			if (c == 0)return nowCount;
			if (c == toK)
			{
				sz[i] = 0;
				if (sz[i + 1] == 0)return nowCount;
				szPtr[nowCount] = sz + i + 1;
				nowCount++;
				if (nowCount >= maxPtr)return nowCount;
			}
		}
		return nowCount;
	}

	void clsUtil::ValueString(string* s, bool* bValue)
	{
		if (*s == "")
		{
			if (*bValue)
				*s = "true";
			return;
		}

		string s____ = clsUtil::TryDeleteDoubleQuotation(*s);
		if (s____ == "true")
			*bValue = true;
		else
			*bValue = false;
	}

	
	void clsUtil::ToXMLString(std::string &s)
	{
		const char *str1 = s.c_str();
		if (strstr(str1, "&"))
		{
			s = clsUtil::CharReplace(s, "&", "&amp;");
			str1 = s.c_str();
		}
		if (strstr(str1, "<"))
		{
			s = clsUtil::CharReplace(s, "<", "&lt;");
			str1 = s.c_str();
		}
		if (strstr(str1, ">"))
		{
			s = clsUtil::CharReplace(s, ">", "&gt;");
			str1 = s.c_str();
		}
		if (strstr(str1, "\""))
		{
			s = clsUtil::CharReplace(s, "\"", "&quot;");
			str1 = s.c_str();
		}
		if (strstr(str1, "\r"))
		{
			s = clsUtil::CharReplace(s, "\r", "");
			str1 = s.c_str();
		}
		if (strstr(str1, "\n"))
		{
			s = clsUtil::CharReplace(s, "\n", "");
			str1 = s.c_str();
		}
		if (strstr(str1, "'"))
		{
			s = clsUtil::CharReplace(s, "'", "&apos;");
			//str1=s.c_str();
		}
		return;
	}

	void clsUtil::ToJSONString(std::string &s)
	{
		const char *str1 = s.c_str();
		if (strstr(str1, "\\"))
		{
			s = clsUtil::CharReplace(s, "\\", "\\\\");
			str1 = s.c_str();
		}
		if (strstr(str1, "/"))
		{
			s = clsUtil::CharReplace(s, "/", "\\/");
			str1 = s.c_str();
		}
		if (strstr(str1, "\""))
		{
			s = clsUtil::CharReplace(s, "\"", "\\\"");
			str1 = s.c_str();
		}
		if (strstr(str1, "\\r"))
		{
			s = clsUtil::CharReplace(s, "\\r", "");
			str1 = s.c_str();
		}
		if (strstr(str1, "\\n"))
		{
			s = clsUtil::CharReplace(s, "\\n", "");
			str1 = s.c_str();
		}
		if (strstr(str1, "\r"))
		{
			s = clsUtil::CharReplace(s, "\r", "");
			str1 = s.c_str();
		}
		if (strstr(str1, "\n"))
		{
			s = clsUtil::CharReplace(s, "\n", "");
			str1 = s.c_str();
		}
		if (strstr(str1, "\t"))
		{
			s = clsUtil::CharReplace(s, "'", "\\t");
			//str1=s.c_str();
		}
		return;
	}

	string clsUtil::CharReplace(string strsrc, string strfind, string strrep)
	{
		 for(string::size_type   pos(0);   pos!=string::npos;   pos+=strrep.length())   {     
            if(   (pos=strsrc.find(strfind,pos))!=string::npos   )     
                strsrc.replace(pos,strfind.length(),strrep);     
            else   break;     
        }
        return   strsrc;   
	}

	std::string  clsUtil::fmt(char* fmt, ...)
	{
		va_list argptr;
		int cnt;
		char buffer[2000];
		va_start(argptr, fmt);

		cnt = vsnprintf(buffer, 1000, fmt, argptr);

		va_end(argptr);

		return buffer;
	}

	std::string  clsUtil::fmt(const char* fmt, ...)
	{
		va_list argptr;
		int cnt;
		char buffer[2000];
		va_start(argptr, fmt);

		cnt = vsnprintf(buffer, 1000, fmt, argptr);

		va_end(argptr);

		return buffer;
	}



	void clsUtil::ValueString(string* s, double* dValue)
	{
		if (*s == "")
		{
			//char buf[500];
			string str = clsUtil::fmt("%lf", *dValue);
			*s = str.c_str();
			return;
		}

		string s____ = clsUtil::TryDeleteDoubleQuotation(*s);
		*dValue = stod(s____.c_str());
	}



	void clsUtil::ValueString(string* s, long* lValue)
	{
		if (*s == "")
		{
			//char s_[500];
			string str = clsUtil::fmt("%ld", lValue);
			*s = str.c_str();
			return;
		}
		string s____ = clsUtil::TryDeleteDoubleQuotation(*s);
		*lValue = stol(s____.c_str());
	}

	void clsUtil::ValueString(string* s, string* sValue)
	{
		if (*s == "")
		{
			string s_ = "";
			s_ += "\"";
			s_ += *sValue;
			s_ += "\"";
			*s = s_;
			return;
		}
		string s____ = clsUtil::TryDeleteDoubleQuotation(*s);
		const char* s_ = s____.c_str();
		int len = strlen(s_);
		clsMalloc clsM(len - 1);
		char* ss = clsM.mem;
		memcpy(ss, s_ + 1, len - 2);
		ss[len - 2] = 0;
		*sValue = ss;
	}

	void clsUtil::EnumString(string* s, int* iEnum, string s1, string s2, string s3, string s4, string s5, string s6, string s7, string s8, string s9, string s10, string s11, string s12)
	{
		if (*s == "")
		{
			switch (*iEnum)
			{
			case 0: *s = s1; break;
			case 1: *s = s2; break;
			case 2: *s = s3; break;
			case 3: *s = s4; break;
			case 4: *s = s5; break;
			case 5: *s = s6; break;
			case 6: *s = s7; break;
			case 7: *s = s8; break;
			case 8: *s = s9; break;
			case 9:*s = s10; break;
			case 10:*s = s11; break;
			case 11:*s = s12; break;
			default:
				*s = "";
				break;
			}
			return;
		}

		string s_ = clsUtil::TryDeleteDoubleQuotation(*s);
		if (s_ == s1) { *iEnum = 0; return; }
		if (s_ == s2) { *iEnum = 1; return; }
		if (s_ == s3) { *iEnum = 2; return; }
		if (s_ == s4) { *iEnum = 3; return; }
		if (s_ == s5) { *iEnum = 4; return; }
		if (s_ == s6) { *iEnum = 5; return; }
		if (s_ == s7) { *iEnum = 6; return; }
		if (s_ == s8) { *iEnum = 7; return; }
		if (s_ == s9) { *iEnum = 8; return; }
		if (s_ == s10) { *iEnum = 9; return; }
		if (s_ == s11) { *iEnum = 10; return; }
		if (s_ == s12) { *iEnum = 11; return; }
		iEnum = 0; return;

	}

	void clsUtil::ColorString(string* s, unsigned  int* iColor)
	{
		if (*s == "")
		{
			unsigned char r, g, b, a;
			a = ((char*)iColor)[3];
			r = ((char*)iColor)[2];
			g = ((char*)iColor)[1];
			b = ((char*)iColor)[0];
			//char s_[1000];
			string str = clsUtil::fmt("%d,%d,%d,%d", r, g, b, a);
			*s = str.c_str();
			return;
		}

		string s____ = clsUtil::TryDeleteDoubleQuotation(*s);
		const char* s_ = s____.c_str();
		int len = strlen(s_);
		char ss[1000];
		memcpy(ss, s_, len + 1);
		char* sRGBA[4];
		clsUtil::ParseStringTok(ss, ',', sRGBA, 4);
		char* sr, *sg, *sb, *sa;
		sr = sRGBA[0]; sg = sRGBA[1]; sb = sRGBA[2]; sa = sRGBA[3];
		int r, g, b, a;
		r = stoi(sr);
		g = stoi(sg);
		b = stoi(sb);
		a = stoi(sa);
		*iColor = (unsigned int)((r << 16) + (g << 8) + b + (a << 24));
	}
}