| 12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- #!/usr/bin/python
- # -*- coding: utf-8 -*-
- import sys
- import platform
- def FormatStdoutString(content):
- """
- 代码中写的string默认设置成utf-8
- 而调试输出可能编码不一样,则需要转换
- """
- if sys.stdout.encoding == 'cp936':
- content = content.decode('utf-8').encode('cp936')
- elif sys.stdout.encoding == 'gb2312':
- content = content.decode('utf-8').encode('cp936')
- elif sys.stdout.encoding == 'utf-8':
- content = content
- return content
- def SplitSpaceInString(content):
- """
- 剔除字符串中所有空白字符
- """
- return ''.join(content.split())
- def FormatStringPlatform(content):
- platformName = platform.system()
- if platformName == 'Windows':
- return content.decode('utf-8').encode('cp936')
- else:
- return content
- def FormatStdinString(content):
- if sys.stdout.encoding == 'cp936':
- content = content.decode('cp936').encode('utf-8')
- elif sys.stdout.encoding == 'gb2312':
- content = content.decode('cp936').encode('utf-8')
- elif sys.stdout.encoding == 'utf-8':
- content = content
- return content
|