Skip to content

RobTillaart/wordCount

Repository files navigation

Arduino CI Arduino-lint JSON check GitHub issues

License: MIT GitHub release PlatformIO Registry

wordCount

Arduino library for creating a wordCounter.

Description

Experimental

This library is a wordCount wrapper around an Arduino stream. It allows to count the bytes, words and digits e.g. for Ethernet packets that are written. The counting is (for now) only done on the output (Print) side.

The internal counters can be requested after every print() or println() statement. It is also possible to reset() the counters to zero at any moment. statement

The idea is derived from the UNIX/Linux wordCount program wc.

This library is originally written for educational purpose. As it might be useful, I decided to (clean up) and publish it.

Feedback as always is welcome.

Related

Just other "stream wrapping" libraries

Tested

Example works on Arduino UNO. Not tested on other platforms. Values seem to be correct so far, note println() can add both a \n and a \r, so the char counter could be +1.

Interface

#include "wordCount.h"

Constructor

  • wordCount(Stream * stream = &Serial) constructor
  • void reset() - resets counters and start time for throughput measurements.

Core

  • uint32_t chars() idem.
  • uint32_t digits() idem.
  • uint32_t lines() idem.
  • uint32_t words() idem.

Throughput

  • float bytesPerSecond() idem.
  • float Bps() Bytes per second
  • float kBps() kiloBytes per second
  • float MBps() MegaBytes per second
  • float wordsPerSecond() idem.
  • float linesPerSecond() idem.

Statistics

  • float averageCharsPerLine() idem (includes \n\r).

Future

Must

  • improve documentation

Should

  • add examples

Could

  • investigate new functions.
    • average word length (difficult!)
    • add user defined counter e.g. count a user defined char e.g. @ or !
    • printable(), non-printable, ASCII, "above 127"
    • call back on user defined char / substring?
    • float averageCharsPerLine() corrected for \n\r?
  • create unit tests. Lorum ipsum

Wont

Support

If you appreciate my libraries, you can support the development and maintenance. Improve the quality of the libraries by providing issues and Pull Requests, or donate through PayPal or GitHub sponsors.

Thank you,

About

Arduino library for creating a wordCounter.

Resources

License

Stars

Watchers

Forks

Sponsor this project

  •  

Packages

 
 
 

Contributors

Languages