Rust Text Processing: Characters, Strings, and Conversions

e81 cse 542s n.w
1 / 7
Embed
Share

Explore the world of text processing in Rust with a focus on characters, strings, and conversions. Learn about Unicode code points, string ownership, character methods, string comparisons, text iterators, formatting, and parsing. Enhance your Rust programming skills in text manipulation and analysis.

  • Rust Programming
  • Text Processing
  • Characters
  • Strings
  • Conversions

Uploaded on | 1 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. E81 CSE 542S: Concurrency and Memory Safe System Software Development Strings and Text Department of Computer Science & Engineering Chris Gill cdgill@wustl.edu 1

  2. Characters and Strings in Rust In Rust a char is a Unicode code point With ASCII and Latin-1 as disjoint subranges Helper methods help classify those, e.g., if c.is_ascii_alphanumeric() {...} A String is an owned text segment let s = Hello, world! .to_string(); A string slice is a borrowed text segment let t = Hello, world! ; // type &str 2 CSE 542S Concurrency and Memory Safe System Software Development

  3. Character Conversions Rust provides methods for conversions E.g., from_digit, to_digit, to_lowercase You can also write your own conversions E.g., using arms of a match expression when checking for palindromes in French: match c { // note inclusive range use ... ' '..=' ' => {return 'a'} ... _ => {return c} } 3 CSE 542S Concurrency and Memory Safe System Software Development

  4. Creating and using Strings Rust has many ways to create a String E.g., from a string slice via to_string E.g., from an iterator via collect Can compare strings for equivalence etc. E.g., if s == t {...} Can transform and then compare them if s.to_lowercase() == t.to_lowercase() {...} 4 CSE 542S Concurrency and Memory Safe System Software Development

  5. Iterators over Text Rust text iterators are generally available E.g., chars() method of a string slice gives an iterator over individual characters in it E.g., lines() method of a string slice gives iterator over line-break delimited sub-slices Adapters then can be applied to those E.g., rev() to get a reverse iterator E.g., map() or filter() to transform or prune out characters within the text 5 CSE 542S Concurrency and Memory Safe System Software Development

  6. Formatting and Parsing Text The format! macro has many uses E.g., can append values to to a string slice E.g., can column-align numeric values E.g., can print out box or reference address The regex crate helps you parse text You construct a regex::Regex and apply it to text and determine whether it matches May involve different forms of normalization for slices with characters like ' in them 6 CSE 542S Concurrency and Memory Safe System Software Development

  7. Studio 16 Examine how Rust supports String and string slice representations of text Practice using iterators and closures to detect palindromes in English and French Studios 12 through 20 are due by 11:59pm on the night before Exam 2 Submit as soon as each is done so you get feedback and can resubmit any that may be marked incomplete 7 CSE 542S Concurrency and Memory Safe System Software Development

More Related Content