- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是我想知道为什么没有基本 C99 函数的任务之一某个名为 namesafe( char *in) 的地方就可以完成这项工作。这会很好在完美的世界中,对于用 UTF-8 希伯来语或 UTF-8 书写的名称完全没用也许是希腊语。然而,假设我被七位 ASCII 困住了,然后我尝试了以下:
/* We may even go so far as to ensure that any apostrophe, or hyphen
* or period may only appear as single entities and not as two or three
* in a row. This does not, however, protect us from total non-sense
* such as D'Archy Mc'Clo.u. d.
*
* walk the first_name string and throw away everything that is
* not in the range A-Z or a-z, with the exception of space char which
* we keep. Also a single hyphen is allowed.
*
* This all seems smart but we are not protected from stupidity such
* As a name with spaces and dashes or hypens intermixed with letters
* or from the artist formally known as 'Prince'.
*/
char buffer[256];
j = 0;
for ( k=0; k<strlen(first_name); k++ ) {
/* Accept anything in the a - z letters */
if ( ( first_name[k] >= 'a' ) && ( first_name[k] <= 'z' ) )
buffer[j++] = first_name[k];
/* Accept anything in the A - Z letters */
if ( ( first_name[k] >= 'A' ) && ( first_name[k] <= 'Z' ) )
buffer[j++] = first_name[k];
/* reduce double dashes or hyphens to a single hyphen */
while (( first_name[k] == '-' ) && ( first_name[k+1] == '-' ))
k++;
if ( first_name[k] == '-' ) /* do I need this ? */
buffer[j++] = first_name[k];
/* reduce double spaces to a single space */
while (( first_name[k] == ' ' ) && ( first_name[k+1] == ' ' ))
k++;
if ( first_name[k] == ' ' ) /* do I also need this ? */
buffer[j++] = first_name[k];
}
/* we may still yet have terminating spaces or hyphens on buffer */
while ( ( j > 1 ) && (( buffer[j-1] == ' ' ) || ( buffer[j-1] == '-' )) )
j--;
buffer[j] = '\0';
/* Accept this new cleaner First Name */
strcpy ( first_name, buffer );
只要输入名称缓冲区不超过 255,似乎就可以很好地工作字符长度。然而,在第一次通过时,我想知道如何摆脱前导空格和诸如破折号和连字符以及可能的撇号的混合之类的噪音?
所以问题是......如何让它变得更好,而且我是否需要这些行我在哪里询问 (first_name[k] == '-') 是否与空格相同?我已经做了在缓冲区上行走寻找重复项并且应该落在连字符上或单个空格。正确的?
最佳答案
纯粹将其视为如何清理代码的抽象编程问题,您可以使用 isalpha()
来确保缓冲区仅包含字母表中的字母、单个连字符和单个空格:
for (k = 0; k < strlen(first_name); k++) {
if (isalpha (first_name[k])
buffer [j++] = first_name[k++];
else if (( first_name[k] == '-' ) && (isalpha (first_name [k+1])))
buffer [j++] = first_name[k++];
else if (( first_name[k] == ' ' ) && (isalpha (first_name [k+1])))
buffer [j++] = first_name[k++];
else
k++;
}
这只是一个草稿。我还没有实际尝试过,所以不能保证。此外,这也无法正确处理像“John - Paul”这样的名字在连字符前后都带有空格的情况;你最终会得到一个空格而不是一个连字符。如果您想捕获此类边缘情况,您可以添加几个额外的“else”子句。
也就是说,作为一个具体的现实解决方案,我同意最好将名称完全按照输入来处理。我自己有一个不寻常的名字,我厌倦了向人们解释是的,这确实是我的名字,不,你不能改变它以适应你对可接受的名字的想法。
关于c - 试图确保字符串缓冲区是一个合理的人名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18090965/
我有以下对象: dog = { location: { x: 52.1089, y: 16.2323 }, f: function(message) { alert
在 TSQL 中,如果我要搜索有效的 .com 电子邮件地址,我需要确保有一个 @ 符号,它以 .com 结尾,并且在 @ 前后至少有一个字符。 SELECT * FROM CUSTOMER WHER
我正在尝试准备一个信用卡交易列表,以便在 Excel 2010 中进行透视和进一步分析(满足个人需求)。问题是我的银行机构没有遵循标准的日期格式,所以有时日期会显示为 Jun. 1, 2013 , 有
看来您不能在 riak 中进行交易。如何确保数据正确? 假设我们要插入评论。在 redis 我会做 commentId=incr commentCount multi SET comment_post
对于下面给定的模式,是否可以确保至少一个属性包含一个值(即 minLength 为 1): { "$schema": "http://json-schema.org/draft-04/sche
我计划在 Haxe 的一个子集中编写 Haxe 库,这些库将编译为每种 Haxe 目标语言。有什么方法可以验证 Haxe 程序是否可以编译为所有目标语言,是否可以在不手动测试每个目标平台上的编译代码的
如果浏览器窗口未聚焦,则当前页面上的所有 webdriver 标识都失败。 如何使用 webdriver 使浏览器成为焦点? 最佳答案 ((JavascriptExecutor) webDriver)
我从这样的 HTML GET 请求中获取图像链接... www.example.com?image=www.anotherdomain.com/image.jpg if (isset($_GET['i
我有一个 eunit 测试,它生成一个唯一的节点名称并开始分发: {A,B,C} = now(), Nodename = list_to_atom(lists:flatten(io_lib:forma
我正在完成我的 iPhone 应用程序。我只是担心我们的网络服务器级别的安全性。数据通过网络服务被传送到 iPhone 应用程序。 我可以在网络服务上采取哪些安全措施,以免受到攻击? 谢谢 最佳答案
我正在编写一个应用程序,该应用程序启动一个运行简单 Web 服务器的子进程。我正在使用 NSTask 并通过管道与其进行通信,一切看起来或多或少都很好。但是,如果我的程序崩溃,子进程将保持事件状态,并
我有一些应用程序,我调用 ShowMessage('Complete!');在长时间操作结束时。 大多数时候,这效果很好,但每隔一段时间,消息对话框就会显示在主窗体后面。 有什么方法可以确保 Show
我通过将消息插入集合并让模板使用 {{#each}} 打印出集合来创建一个简单的聊天。 我不太熟悉安全性,但是有没有办法让它符合 EFF 规定? https://www.eff.org/secure-
我有一个商店,我想在其中正确管理 id。假设我有以下帖子存储: type Post = { id: number; title: string; body?: string; } type
我有一个使用 ajax post 方法和数据表的程序。经过几周的摆弄,我确定我根本不明白 javascript 是如何工作的。这是我的 JavaScript: $('#SaveTimeSheet').
我有一个系统,如果从 Azure 服务总线丢失消息将是一场灾难,也就是说,数据将永远丢失,并且没有实际方法可以在不造成重大中断的情况下修复损坏。 在这种情况下我可以完全依赖 ASB 吗? (即使它
如何确保 scalatest 测试不会并行运行?在 0.12 之前,我有一个 sbt 设置: parallelExecution in Test := false 新版本引入了一些复杂的机制。这种更简
我的端点有两个如下所示的 promise : request.post({ url: url, json: smsSTART, header
简短版本 当 ui-router 转换到新 View 时(以我不完全理解的方式使用 ngAnimate),它会添加类 ng-leave 和 ng-leave-active 到当前 View 。它还将类
目前正在努力寻找验证 2 个表的方法(有效地验证表 A 的大量行) 我有两张 table 表A ID A B C 表格匹配 ID Number A 1 A 2 A 9 B 1
我是一名优秀的程序员,十分优秀!