Utils.cpp
资源名称:vc一个皮肤.zip [点击查看]
上传用户:vipseo
上传日期:2010-02-15
资源大小:137k
文件大小:5k
源码类别:
组合框控件
开发平台:
Visual C++
- // 2002.11.23
- // copy from kdphoto projects
- #include "stdafx.h"
- int GetChar( char ** str )
- {
- int code = **((unsigned char **)str);
- if ( !str ) return 0;
- if ( !*str ) return 0;
- if ( !code ) return 0;
- (*str) ++;
- if ( code > 0x80 )
- {
- code *= 256;
- code += **((unsigned char **)str);
- (*str) ++;
- }
- return code;
- };
- int SetChar( char **str, int chr )
- {
- int byte = 1;
- if ( !str ) return 0;
- if ( !*str ) return 0;
- if ( chr < 256 )
- {
- **((unsigned char **)str) = chr % 256;
- (*str) ++;
- }
- else
- {
- **((unsigned char **)str) = chr / 256;
- (*str) ++;
- **((unsigned char **)str) = chr % 256;
- (*str) ++;
- byte ++;
- }
- return byte;
- }
- int PeekChar( char **str )
- {
- int code = **((unsigned char **)str);
- if ( !str ) return 0;
- if ( !*str ) return 0;
- if ( !code ) return 0;
- if ( code > 0x80 )
- {
- code *= 256;
- code += *((unsigned char *)(*str + 1));
- }
- return code;
- }
- int CatChar( char *str, int cc)
- {
- int len = 0;
- while( *str )
- {
- GetChar( &str );
- len++;
- }
- SetChar( &str, cc );
- *str = 0;
- return (++len);
- }
- char *whitespaces = " tn";
- ///去掉空格的函数
- void trim( char *buf, char *result )
- {
- char * p;
- if ( !buf || !result )
- return;
- p = strlen( buf ) + buf;
- while ( (*buf) && strchr( whitespaces, *buf) ) buf++;
- while( (p >= buf) && strchr( whitespaces, *p) ) p--;
- while ( buf <= p ) *result++ = *buf++;
- *result = 0;
- }
- char *next_token( char *buf, char *token, char *stopchars )
- {
- if ( !stopchars )
- stopchars = whitespaces;
- int cc;
- char *p = token;
- while ( (cc = GetChar(&buf)) && (!strchr( stopchars, cc)) )
- SetChar( &token, cc);
- SetChar( &token, 0);
- trim( p, p );
- return buf;
- }
- CString GetPathName( const char * filename )
- {
- /*
- CString path = filename;
- char *file = path.GetBuffer(512);
- char *p = file + strlen( file );
- for ( ; *p != '\' && *p != '/' && p > file; p-- );
- if ( *p == '\' || *p == '/') p++;
- *p = 0;
- path.ReleaseBuffer();
- */
- char path[MAX_PATH];
- strcpy( path, filename );
- char *p = path + strlen( path );
- for ( ; *p != '\' && *p != '/' && p > path; p-- );
- if ( *p == '\' || *p == '/') p++;
- *p = 0;
- return CString(path);
- }
- ///获取文件扩展名
- const char * GetExt( const char * filename )
- {
- const char *p = strlen(filename) + filename;
- while( p > filename && *p != '.' ) p--;
- if ( *p != '.' )
- return "