⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stringset.h

📁 基于MFC和STL平台的字符串类
💻 H
字号:
// StringSet.H: interface for the CIVStringSet class.
//
// Written 30 June 2002 by Scot T Brennecke
// Thanks to Moishe Halibard and Moshe Rubin for their article,
//    "A Multiple Substring Search Algorithm" in the June 2002
//    edition of C/C++ Users Journal.  This class is based on
//    the algorthim therein described, but extended to return
//    all strings and use MFC classes.

#pragma once

#pragma warning(disable: 4100 4786)
#include <vector>
#include <string>
#include <list>

class CIVStringSet : public std::vector<std::string>
{
    public:
        CIVStringSet( WORD wInitialWidth = 64 ) ;  // Initial width of FSM
        virtual ~CIVStringSet() ;

        bool        Add( LPCTSTR pszWord ) ;                     // a single word
        bool        Add( const std::string & rstrWord ) ;        // a single word
        int         Add( LPCTSTR pszWords, LPCTSTR pszDelims ) ; // multiple words, delimited with chars from pszDelims
        int         Add( LPCTSTR pszzWords, int nWords ) ;       // nWords words, each 0 term'd, with extra 0 at end
        int         Add( std::vector<std::string> astrWords ) ;  // all the elements of an array of strings
        int         Add( std::list<std::string> lstrWords ) ;    // all the elements of a list of strings
                    
        UINT        FindFirstIn( std::string strText, int & rnFirst ) ; // Begin iteration
        UINT        FindNext( int & rnNext ) ;                          // Continue interation

        typedef std::pair<int,UINT>              CWordPosPair ;     // first is index of word in array, second is position in text
        typedef std::list< std::pair<int,UINT> > CWordPosPairList ; // list of pairs to be returned by FindAllIn
        size_t      FindAllIn( std::string strText, CWordPosPairList & rlstrWords ) ; // Iterate all at once and make list
        
    protected:
        DWORD    (* m_apnFSM)[128] ;   // Finite State Machine. Array of 128 char arrays
        size_t      m_nCurDim ;        // Dimension of allocated width of FSM
        size_t      m_nUsedCols ;      // Used portion of allocated width
        WORD        m_wMaxUsedState ;  // largest state value used
        std::string m_strSearch ;      // Current search string
        UINT        m_nCurTextChar ;   // Current position in search string

        bool        InsertWord( LPCTSTR pszWord, WORD wIndex ) ; // put the new word into the FSM for given index
        bool        SetColDim( size_t nNewDim ) ;                // set the current width to at least nNewDim columns
} ;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -