Click here to Skip to main content
Licence CPOL
First Posted 11 May 2003
Views 51,558
Bookmarked 18 times

XMemString - Extended memory and string search functions

By | 11 May 2003 | Article
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)

    About the Author

    Hans Dietrich

    Software Developer (Senior)
    Hans Dietrich Software
    United States United States

    Member

    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.







    Sign Up to vote   Poor Excellent
    Add a reason or comment to your vote: x
    Votes of 3 or less require a comment

    Comments and Discussions

     
    You must Sign In to use this message board. (secure sign-in)
     
    Search this forum  
     FAQ
        Noise  Layout  Per page   
      Refresh
    QuestionThank you! PinmemberOmidOnTop2:06 27 Jan '12  
    Generalmultibyte woes Pinmemberumeca7422:08 19 May '03  
    GeneralRe: multibyte woes PinmemberHans Dietrich8:00 21 May '03  
    QuestionWhy should I use it? PinmemberRené Greiner22:22 11 May '03  
    AnswerRe: Why should I use it? Pinmemberdog_spawn4:10 12 May '03  
    AnswerRe: Why should I use it? PinmemberSam Levy7:31 12 May '03  
    GeneralRe: Why should I use it? Pinmemberdog_spawn9:36 12 May '03  
    GeneralRe: Why should I use it? PinmemberSam Levy10:56 12 May '03  
    GeneralRe: Why should I use it? Pinmemberdog_spawn14:28 12 May '03  
    GeneralThank you! Pinmemberjunksmi0:45 28 Aug '05  
    GeneralRe: Thank you! PinmemberHans Dietrich8:01 29 Aug '05  

    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.

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