设为首页 加入收藏

TOP

4.4 A C++ Implementation(3)
2013-10-07 14:27:06 来源: 作者: 【 】 浏览:57
Tags:4.4 Implementation

图4.4 A C++(www.cppentry.com) Implementation(4) 

Since strcspn doesn’t work on C++(www.cppentry.com) strings, we must change both split and advquoted. The new version of advquoted uses the C++(www.cppentry.com) standard func- tion find_first_of to locate the next occurrence of a separator character. The call s.find_first_of(fieldsep,j) searches the string s for the first instance of any character in fiel dsep that occurs at or after position j. If it fails to find an instance, it returns an index beyond the end of the string, so we must bring it back within range. The inner for loop that follows appends characters up to the separator to the field being accumulated in fld.

图4.4 A C++(www.cppentry.com) Implementation(5) 

The function find_first_of is also used in a new function advplain, which advances over a plain unquoted field. Again, this change is required be- cause C string functions like strcspn cannot be applied to C++(www.cppentry.com) strings, which are an entirely different data type.

图4.4 A C++(www.cppentry.com) Implementation(6) 

图4.4 A C++(www.cppentry.com) Implementation(7) 

As before, Csv::getfield is trivial, while Csv::getnfield is so short that it is implemented in the class definition.


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇4.4 A C++ Implementation(4) 下一篇4.4 A C++ Implementation(2)

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: