Git Product home page Git Product logo

cpp_string's Introduction

Custom String Class

Overview

A custom string class that implements strings in the C/C++ environment without NULL termination. It is a proper object that contains the string data and its length. Using these, both read and write methods are provided, as well as other expected string commands, such as upcasing, downcasing, or character indexing.

An improvement for this exercise would be to incorporate more string methods, such as those exemplified in the Python string class: https://docs.python.org/3/library/string.html

This project does not attempt to provide an improvement over C strings or the C++ string library. This is purely for pedagogical purposes.

This is an update to my CISP 430 Data Structures class assignment from American River College taught by the great David Fox.

String API

Constructors

String ( )                // Empty String default constructor
String (char)             // Character String constructor
String (const char*)      // Character array String constructor
String (const String& s)  // Copy constructor

Informational Methods

unsigned   len ( ) const     // String length
     int index (char) const  // Find character index

Case Methods

void     upcase (unsigned first, unsigned last)  // Uppercase String within range
void   downcase (unsigned first, unsigned last)  // Lowercase String within range
void togglecase (unsigned first, unsigned last)  // Toggle case within range

Stream Operators

friend std::ostream& operator<< (std::ostream&, const String&)  // cout << String 
friend std::istream& operator>> (std::istream&, String&)        // cin >> String

Accessor Operators

 char operator[] (unsigned) const  // Reference access
char& operator[] (unsigned)        // Copy access

Assignment Operators

String&  operator= (const String&)  // Assign new String
String& operator+= (const String&)  // Assign concatenated String

String Concatenation

friend String operator+ (const String&, const String&)  // Concat two Strings
friend String operator+ (const String&, char)           // Concat a String and character
friend String operator+ (const String&, const char*)    // Concat a String and C-string
friend String operator+ (char, const String&)           // Concat a character and String
friend String operator+ (const char*, const String&)    // Concat a C-string and String

Logical Operators

All argument permutations in concatenation are repeated here, also.

friend bool operator== (const String&, const String&)  // Equality
friend bool operator!= (const String&, const String&)  // Non-Equality
friend bool  operator< (const String&, const String&)  // Less-than Inequality
friend bool  operator> (const String&, const String&)  // Greater-than Inequality
friend bool operator<= (const String&, const String&)  // Less-than or Equailty
friend bool operator>= (const String&, const String&)  // Greater-than or Equality

cpp_string's People

Contributors

bryangoodrich avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.