tsv.rs 507 B

1234567891011121314151617181920212223242526
  1. pub fn split_first<'a>(line: &'a str) -> Option<(&'a str, &'a str)> {
  2. match line.find('\t') {
  3. Some(i) => Some((&line[0..i], &line[(i+1)..])),
  4. None => None
  5. }
  6. }
  7. #[test]
  8. fn split_empty() {
  9. assert_eq!(split_first(""), None)
  10. }
  11. #[test]
  12. fn split_tab() {
  13. assert_eq!(split_first("foo\tbar"), Some(("foo", "bar")))
  14. }
  15. #[test]
  16. fn split_end() {
  17. assert_eq!(split_first("foo\t"), Some(("foo", "")))
  18. }
  19. #[test]
  20. fn split_2() {
  21. assert_eq!(split_first("foo\tbar\tblatz"), Some(("foo", "bar\tblatz")))
  22. }
Tip!

Press p or to see the previous file or, n or to see the next file