[英]c++ - escape special characters
I need to escape all special characters and replace national characters and get "plain text" for a tablename. 我需要转义所有特殊字符并替换国家字符,并为表名获取“纯文本”。
string getTableName(string name)
My string could be "šárka65_%&." 我的字符串可能是“šárka65_%&”。 and I want to get string I can use in my database as a tablename.
并且我想获取可以在数据库中用作表名的字符串。
Which DBMS? 哪个DBMS?
You could simply choose to enclose the name in the appropriate markers. 您可以选择将名称括在适当的标记中。
I had a feeling that wasn't what you wanted... 我觉得那不是你想要的...
What codeset is your string in? 您的字符串在哪个代码集中? It seems to be UTF-8 by the time it gets to my browser.
到达我的浏览器时似乎是UTF-8。 Do you need to be able to invert the mapping unambiguously?
您是否需要能够明确地反转映射? That is harder.
那更难了。
You can use many schemes to map the information: 您可以使用多种方案来映射信息:
One simple minded one is simply to hex-encode everything, using a marker (X) to protect against leading digits: 一个简单的想法就是使用标记(X)防止所有前导数字对所有内容进行十六进制编码:
XC5A1C3A1726B6136355F25262E
One slightly less simple minded one is hex-encode anything that is not already an ASCII alphanumeric or underscore. 一个不太简单的想法是十六进制编码任何不是ASCII字母数字或下划线的东西。
XC5A1C3A1rka65_25262E
Or, as a comment suggests, you can devise a mapping table for accented Latin letters - indeed, a mapping table appropriately initialized will be the fastest approach. 或者,正如评论所建议的那样,您可以为重音拉丁字母设计一个映射表-实际上,适当初始化的映射表将是最快的方法。 The input is the character in the source string;
输入是源字符串中的字符; the output is the desired mapped character or characters.
输出是所需的一个或多个映射字符。 If you use an 8-bit character set, this is entirely manageable.
如果使用8位字符集,则完全可以管理。 If you use full Unicode, it is a lot less manageable (not least, how do you map all the Han syllabary to ASCII?).
如果您使用完整的Unicode,则它的可管理性要低得多(特别是,您如何将所有汉字音节映射到ASCII?)。
Or ... 要么 ...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.