Click here to Skip to main content
Click here to Skip to main content

XMemString - Extended memory and string search functions

, 11 May 2003 CPOL
Rate this:
Please Sign up or sign in to vote.
Extended string and memory search functions: memmem(), memimem(), memichr(), _tcsistr()
  • Download demo project - 21 Kb

    Introduction

    XMemString is a collection of memory and string search functions I have been using for many years. They are all modelled on the functions available in the standard C runtime, so they are fairly self-explanatory.

    Function Descriptions

    • memichr() - Find character in a buffer (case insensitive).
      ///////////////////////////////////////////////////////////////////////////////
      //
      // memichr()
      //
      // Purpose:     Find character in a buffer (case insensitive)
      //
      // Parameters:  buf      - pointer to buffer
      //              c        - character to look for
      //              buf_len  - size of buffer in bytes
      //
      // Returns:     void *   - if successful, returns a pointer to the first
      //                         occurrence of c in buf;  otherwise, returns NULL
      //
      // Notes;       memichr() will search by ignoring the case of those characters
      //              that fall in the ANSI range a-z and A-Z.
      // 
    • memimem() - Find a byte sequence within a memory buffer (case insensitive)
      ///////////////////////////////////////////////////////////////////////////////
      //
      // memimem()
      //
      // Purpose:     Find a byte sequence within a memory buffer (case insensitive)
      //
      // Parameters:  buf               - pointer to buffer
      //              buf_len           - size of buffer in bytes
      //              byte_sequence     - byte sequence to look for
      //              byte_sequence_len - size of byte sequence in bytes
      //
      // Returns:     void * - if successful, returns a pointer to the first
      //                       occurrence of byte_sequence in buf;  otherwise,
      //                       returns NULL
      //
      // Notes;       memimem() will search by ignoring the case of those characters
      //              that fall in the ANSI range a-z and A-Z.
      //
      
    • memmem() - Find a byte sequence within a memory buffer
      ///////////////////////////////////////////////////////////////////////////////
      //
      // memmem()
      //
      // Purpose:     Find a byte sequence within a memory buffer
      //
      // Parameters:  buf               - pointer to buffer
      //              buf_len           - size of buffer in bytes
      //              byte_sequence     - byte sequence to look for
      //              byte_sequence_len - size of byte sequence in bytes
      //
      // Returns:     void * - if successful, returns a pointer to the first
      //                       occurrence of byte_sequence in buf;  otherwise,
      //                       returns NULL
      //
      // Notes;       Characters in byte_sequence and characters in buf will be
      //              compared "as is", with no case conversion.
      // 
    • _tcsistr() - Find a substring within a string (case insensitive)
      ///////////////////////////////////////////////////////////////////////////////
      //
      // _tcsistr()
      //
      // Purpose:     Find a substring within a string (case insensitive)
      //
      // Parameters:  string     - nul-terminated string to search
      //              strCharSet - nul-terminated string to search for
      //
      // Returns:     void * - if successful, returns a pointer to the first
      //                       occurrence of strCharSet in string;  otherwise,
      //                       returns NULL
      //
      // Notes;       _tcsistr() will search by ignoring the case of those characters
      //              that fall in the ANSI range a-z and A-Z.
      // 

    How To Use

    To integrate XMemString functions into your app, you first need to add following files to your project:

    • XMemString.cpp
    • XMemString.h

    If you include XMemString in project that uses precompiled headers, you must change C/C++ Precompiled Headers settings to Not using precompiled headers for XMemString.cpp.

    Next, include the header file XMemString.h in appropriate project files. Now you are ready to start using XMemString. Please see XMemStringTest.cpp for examples.

    Revision History

    Version 1.0 - 2003 May 11

    • Initial public release

    Usage

    This software is released into the public domain. You are free to use it in any way you like. If you modify it or extend it, please to consider posting new code here for everyone to share. This software is provided "as is" with no expressed or implied warranty. I accept no liability for any damage or loss of business that this software may cause.


  • License

    This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Share

    About the Author

    Hans Dietrich
    Software Developer (Senior) Hans Dietrich Software
    United States United States
    I attended St. Michael's College of the University of Toronto, with the intention of becoming a priest. A friend in the University's Computer Science Department got me interested in programming, and I have been hooked ever since.
     
    Recently, I have moved to Los Angeles where I am doing consulting and development work.
     
    For consulting and custom software development, please see www.hdsoft.org.






    Comments and Discussions

     
    QuestionThank you! PinmemberOmidOnTop27-Jan-12 3:06 
    Generalmultibyte woes Pinmemberumeca7419-May-03 23:08 
    GeneralRe: multibyte woes PinmemberHans Dietrich21-May-03 9:00 
    QuestionWhy should I use it? PinmemberRené Greiner11-May-03 23:22 
    AnswerRe: Why should I use it? Pinmemberdog_spawn12-May-03 5:10 
    AnswerRe: Why should I use it? PinmemberSam Levy12-May-03 8:31 
    GeneralRe: Why should I use it? Pinmemberdog_spawn12-May-03 10:36 
    GeneralRe: Why should I use it? PinmemberSam Levy12-May-03 11:56 
    GeneralRe: Why should I use it? Pinmemberdog_spawn12-May-03 15:28 

    General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

    Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

    | Advertise | Privacy | Terms of Use | Mobile
    Web03 | 2.8.1411023.1 | Last Updated 11 May 2003
    Article Copyright 2003 by Hans Dietrich
    Everything else Copyright © CodeProject, 1999-2014
    Layout: fixed | fluid