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

📄 string.h

📁 ac3的解码程序
💻 H
📖 第 1 页 / 共 3 页
字号:
// This may look like C code, but it is really -*- C++ -*-/* Copyright (C) 1988 Free Software Foundation    written by Doug Lea (dl@rocky.oswego.edu)This file is part of the GNU C++ Library.  This library is freesoftware; you can redistribute it and/or modify it under the terms ofthe GNU Library General Public License as published by the FreeSoftware Foundation; either version 2 of the License, or (at youroption) any later version.  This library is distributed in the hopethat it will be useful, but WITHOUT ANY WARRANTY; without even theimplied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULARPURPOSE.  See the GNU Library General Public License for more details.You should have received a copy of the GNU Library General PublicLicense along with this library; if not, write to the Free SoftwareFoundation, 675 Mass Ave, Cambridge, MA 02139, USA.*/#ifndef _String_h#ifdef __GNUG__#pragma interface#endif#define _String_h 1#include <iostream.h>#include <Regex.h>struct StrRep                     // internal String representations{  unsigned short    len;         // string length   unsigned short    sz;          // allocated space  char              s[1];        // the string starts here                                  // (at least 1 char for trailing null)                                 // allocated & expanded via non-public fcts};// primitive ops on StrReps -- nearly all String fns go through these.StrRep*     Salloc(StrRep*, const char*, int, int);StrRep*     Scopy(StrRep*, const StrRep*);StrRep*     Scat(StrRep*, const char*, int, const char*, int);StrRep*     Scat(StrRep*, const char*, int,const char*,int, const char*,int);StrRep*     Sprepend(StrRep*, const char*, int);StrRep*     Sreverse(const StrRep*, StrRep*);StrRep*     Supcase(const StrRep*, StrRep*);StrRep*     Sdowncase(const StrRep*, StrRep*);StrRep*     Scapitalize(const StrRep*, StrRep*);// These classes need to be defined in the order givenclass String;class SubString;class SubString{  friend class      String;protected:  String&           S;        // The String I'm a substring of  unsigned short    pos;      // starting position in S's rep  unsigned short    len;      // length of substring  void              assign(const StrRep*, const char*, int = -1);                    SubString(String& x, int p, int l);                    SubString(const SubString& x);public:// Note there are no public constructors. SubStrings are always// created via String operations                   ~SubString();  SubString&        operator =  (const String&     y);  SubString&        operator =  (const SubString&  y);  SubString&        operator =  (const char* t);  SubString&        operator =  (char        c);// return 1 if target appears anywhere in SubString; else 0  int               contains(char        c) const;  int               contains(const String&     y) const;  int               contains(const SubString&  y) const;  int               contains(const char* t) const;  int               contains(const Regex&       r) const;// return 1 if target matches entire SubString  int               matches(const Regex&  r) const;// IO   friend ostream&   operator<<(ostream& s, const SubString& x);// status  unsigned int      length() const;  int               empty() const;  const char*       chars() const;  int               OK() const; };class String{  friend class      SubString;protected:  StrRep*           rep;   // Strings are pointers to their representations// some helper functions  int               search(int, int, const char*, int = -1) const;  int               search(int, int, char) const;  int               match(int, int, int, const char*, int = -1) const;  int               _gsub(const char*, int, const char* ,int);  int               _gsub(const Regex&, const char*, int);  SubString         _substr(int, int);public:// constructors & assignment                    String();                    String(const String& x);                    String(const SubString&  x);                    String(const char* t);                    String(const char* t, int len);                    String(char c);                    ~String();  String&           operator =  (const String&     y);  String&           operator =  (const char* y);  String&           operator =  (char        c);  String&           operator =  (const SubString&  y);// concatenation  String&           operator += (const String&     y);   String&           operator += (const SubString&  y);  String&           operator += (const char* t);  String&           operator += (char        c);  void              prepend(const String&     y);   void              prepend(const SubString&  y);  void              prepend(const char* t);  void              prepend(char        c);// procedural versions:// concatenate first 2 args, store result in last arg  friend inline void     cat(const String&, const String&, String&);  friend inline void     cat(const String&, const SubString&, String&);  friend inline void     cat(const String&, const char*, String&);  friend inline void     cat(const String&, char, String&);  friend inline void     cat(const SubString&, const String&, String&);  friend inline void     cat(const SubString&, const SubString&, String&);  friend inline void     cat(const SubString&, const char*, String&);  friend inline void     cat(const SubString&, char, String&);  friend inline void     cat(const char*, const String&, String&);  friend inline void     cat(const char*, const SubString&, String&);  friend inline void     cat(const char*, const char*, String&);  friend inline void     cat(const char*, char, String&);// double concatenation, by request. (yes, there are too many versions, // but if one is supported, then the others should be too...)// Concatenate first 3 args, store in last arg  friend inline void     cat(const String&,const String&, const String&,String&);  friend inline void     cat(const String&,const String&,const SubString&,String&);  friend inline void     cat(const String&,const String&, const char*, String&);  friend inline void     cat(const String&,const String&, char, String&);  friend inline void     cat(const String&,const SubString&,const String&,String&);  inline friend void     cat(const String&,const SubString&,const SubString&,String&);  friend inline void     cat(const String&,const SubString&, const char*, String&);  friend inline void     cat(const String&,const SubString&, char, String&);  friend inline void     cat(const String&,const char*, const String&,    String&);  friend inline void     cat(const String&,const char*, const SubString&, String&);  friend inline void     cat(const String&,const char*, const char*, String&);  friend inline void     cat(const String&,const char*, char, String&);  friend inline void     cat(const char*, const String&, const String&,String&);  friend inline void     cat(const char*,const String&,const SubString&,String&);  friend inline void     cat(const char*,const String&, const char*, String&);  friend inline void     cat(const char*,const String&, char, String&);  friend inline void     cat(const char*,const SubString&,const String&,String&);  friend inline void     cat(const char*,const SubString&,const SubString&,String&);  friend inline void     cat(const char*,const SubString&, const char*, String&);  friend inline void     cat(const char*,const SubString&, char, String&);  friend inline void     cat(const char*,const char*, const String&,    String&);  friend inline void     cat(const char*,const char*, const SubString&, String&);  friend inline void     cat(const char*,const char*, const char*, String&);  friend inline void     cat(const char*,const char*, char, String&);// searching & matching// return position of target in string or -1 for failure  int               index(char        c, int startpos = 0) const;        int               index(const String&     y, int startpos = 0) const;        int               index(const SubString&  y, int startpos = 0) const;        int               index(const char* t, int startpos = 0) const;    int               index(const Regex&      r, int startpos = 0) const;       // return 1 if target appears anyhere in String; else 0  int               contains(char        c) const;  int               contains(const String&     y) const;  int               contains(const SubString&  y) const;  int               contains(const char* t) const;  int               contains(const Regex&      r) const;// return 1 if target appears anywhere after position pos // (or before, if pos is negative) in String; else 0  int               contains(char        c, int pos) const;  int               contains(const String&     y, int pos) const;  int               contains(const SubString&  y, int pos) const;  int               contains(const char* t, int pos) const;  int               contains(const Regex&      r, int pos) const;// return 1 if target appears at position pos in String; else 0  int               matches(char        c, int pos = 0) const;  int               matches(const String&     y, int pos = 0) const;  int               matches(const SubString&  y, int pos = 0) const;  int               matches(const char* t, int pos = 0) const;  int               matches(const Regex&      r, int pos = 0) const;//  return number of occurences of target in String  int               freq(char        c) const;   int               freq(const String&     y) const;  int               freq(const SubString&  y) const;  int               freq(const char* t) const;// SubString extraction// Note that you can't take a substring of a const String, since// this leaves open the possiblility of indirectly modifying the// String through the SubString  SubString         at(int         pos, int len);  SubString         operator () (int         pos, int len); // synonym for at  SubString         at(const String&     x, int startpos = 0);   SubString         at(const SubString&  x, int startpos = 0);   SubString         at(const char* t, int startpos = 0);  SubString         at(char        c, int startpos = 0);  SubString         at(const Regex&      r, int startpos = 0);   SubString         before(int          pos);  SubString         before(const String&      x, int startpos = 0);  SubString         before(const SubString&   x, int startpos = 0);  SubString         before(const char*  t, int startpos = 0);  SubString         before(char         c, int startpos = 0);  SubString         before(const Regex&       r, int startpos = 0);  SubString         through(int          pos);  SubString         through(const String&      x, int startpos = 0);  SubString         through(const SubString&   x, int startpos = 0);  SubString         through(const char*  t, int startpos = 0);  SubString         through(char         c, int startpos = 0);  SubString         through(const Regex&       r, int startpos = 0);  SubString         from(int          pos);  SubString         from(const String&      x, int startpos = 0);  SubString         from(const SubString&   x, int startpos = 0);  SubString         from(const char*  t, int startpos = 0);  SubString         from(char         c, int startpos = 0);  SubString         from(const Regex&       r, int startpos = 0);  SubString         after(int         pos);  SubString         after(const String&     x, int startpos = 0);  SubString         after(const SubString&  x, int startpos = 0);  SubString         after(const char* t, int startpos = 0);  SubString         after(char        c, int startpos = 0);  SubString         after(const Regex&      r, int startpos = 0);// deletion// delete len chars starting at pos  void              del(int         pos, int len);// delete the first occurrence of target after startpos  void              del(const String&     y, int startpos = 0);  void              del(const SubString&  y, int startpos = 0);  void              del(const char* t, int startpos = 0);  void              del(char        c, int startpos = 0);  void              del(const Regex&      r, int startpos = 0);// global substitution: substitute all occurrences of pat with repl  int               gsub(const String&     pat, const String&     repl);  int               gsub(const SubString&  pat, const String&     repl);  int               gsub(const char* pat, const String&     repl);  int               gsub(const char* pat, const char* repl);  int               gsub(const Regex&      pat, const String&     repl);// friends & utilities// split string into array res at separators; return number of elements  friend int        split(const String& x, String res[], int maxn,                           const String& sep);  friend int        split(const String& x, String res[], int maxn,                           const Regex&  sep);  friend String     common_prefix(const String& x, const String& y,                                   int startpos = 0);  friend String     common_suffix(const String& x, const String& y,                                   int startpos = -1);  friend String     replicate(char        c, int n);  friend String     replicate(const String&     y, int n);  friend String     join(String src[], int n, const String& sep);// simple builtin transformations  friend inline String     reverse(const String& x);  friend inline String     upcase(const String& x);  friend inline String     downcase(const String& x);  friend inline String     capitalize(const String& x);// in-place versions of above  void              reverse();  void              upcase();  void              downcase();  void              capitalize();// element extraction  char&             operator [] (int i);  const char&       operator [] (int i) const;  char              elem(int i) const;  char              firstchar() const;  char              lastchar() const;// conversion                    operator const char*() const;  const char*       chars() const;// IO  friend inline ostream&   operator<<(ostream& s, const String& x);  friend ostream&   operator<<(ostream& s, const SubString& x);  friend istream&   operator>>(istream& s, String& x);  friend int        readline(istream& s, String& x,                              char terminator = '\n',                             int discard_terminator = 1);// status  unsigned int      length() const;  int               empty() const;// preallocate some space for String  void              alloc(int newsize);// report current allocation (not length!)  int               allocation() const;  void     error(const char* msg) const;  int               OK() const;};typedef String StrTmp; // for backward compatibility// other externsint        compare(const String&    x, const String&     y);int        compare(const String&    x, const SubString&  y);int        compare(const String&    x, const char* y);int        compare(const SubString& x, const String&     y);int        compare(const SubString& x, const SubString&  y);int        compare(const SubString& x, const char* y);int        fcompare(const String&   x, const String&     y); // ignore caseextern StrRep  _nilStrRep;extern String _nilString;// status reports, needed before defining other thingsinline unsigned int String::length() const {  return rep->len; }inline int         String::empty() const { return rep->len == 0; }inline const char* String::chars() const { return &(rep->s[0]); }inline int         String::allocation() const { return rep->sz; }inline unsigned int SubString::length() const { return len; }inline int         SubString::empty() const { return len == 0; }inline const char* SubString::chars() const { return &(S.rep->s[pos]); }// constructorsinline String::String()   : rep(&_nilStrRep) {}inline String::String(const String& x)   : rep(Scopy(0, x.rep)) {}inline String::String(const char* t)   : rep(Salloc(0, t, -1, -1)) {}inline String::String(const char* t, int tlen)  : rep(Salloc(0, t, tlen, tlen)) {}inline String::String(const SubString& y)  : rep(Salloc(0, y.chars(), y.length(), y.length())) {}inline String::String(char c)   : rep(Salloc(0, &c, 1, 1)) {}inline String::~String() { if (rep != &_nilStrRep) delete rep; }inline SubString::SubString(const SubString& x)  :S(x.S), pos(x.pos), len(x.len) {}

⌨️ 快捷键说明

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