Back to index

lightning-sunbird  0.9+nobinonly
nsTSubstringTuple.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* vim:set ts=2 sw=2 sts=2 et cindent: */
00003 /* ***** BEGIN LICENSE BLOCK *****
00004  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00005  *
00006  * The contents of this file are subject to the Mozilla Public License Version
00007  * 1.1 (the "License"); you may not use this file except in compliance with
00008  * the License. You may obtain a copy of the License at
00009  * http://www.mozilla.org/MPL/
00010  *
00011  * Software distributed under the License is distributed on an "AS IS" basis,
00012  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013  * for the specific language governing rights and limitations under the
00014  * License.
00015  *
00016  * The Original Code is Mozilla.
00017  *
00018  * The Initial Developer of the Original Code is IBM Corporation.
00019  * Portions created by IBM Corporation are Copyright (C) 2003
00020  * IBM Corporation. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Darin Fisher <darin@meer.net>
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either the GNU General Public License Version 2 or later (the "GPL"), or
00027  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 
00044 nsTSubstringTuple_CharT::size_type
00045 nsTSubstringTuple_CharT::Length() const
00046   {
00047     PRUint32 len;
00048     if (mHead)
00049       len = mHead->Length();
00050     else
00051       len = TO_SUBSTRING(mFragA).Length();
00052 
00053     return len + TO_SUBSTRING(mFragB).Length();
00054   }
00055 
00056 
00063 void
00064 nsTSubstringTuple_CharT::WriteTo( char_type *buf, PRUint32 bufLen ) const
00065   {
00066     const substring_type& b = TO_SUBSTRING(mFragB);
00067 
00068     NS_ASSERTION(bufLen >= b.Length(), "buffer too small");
00069     PRUint32 headLen = bufLen - b.Length();
00070     if (mHead)
00071       {
00072         mHead->WriteTo(buf, headLen);
00073       }
00074     else
00075       {
00076         const substring_type& a = TO_SUBSTRING(mFragA);
00077 
00078         NS_ASSERTION(a.Length() == headLen, "buffer incorrectly sized");
00079         char_traits::copy(buf, a.Data(), a.Length());
00080       }
00081 
00082     char_traits::copy(buf + headLen, b.Data(), b.Length());
00083 
00084 #if 0
00085     // we need to write out data into |buf|, ending at |buf+bufLen|.  so our
00086     // data needs to precede |buf+bufLen| exactly.  we trust that the buffer
00087     // was properly sized!
00088 
00089     const substring_type& b = TO_SUBSTRING(mFragB);
00090 
00091     NS_ASSERTION(bufLen >= b.Length(), "buffer is too small");
00092     char_traits::copy(buf + bufLen - b.Length(), b.Data(), b.Length());
00093 
00094     bufLen -= b.Length();
00095 
00096     if (mHead)
00097       {
00098         mHead->WriteTo(buf, bufLen);
00099       }
00100     else
00101       {
00102         const substring_type& a = TO_SUBSTRING(mFragA);
00103         NS_ASSERTION(bufLen == a.Length(), "buffer is too small");
00104         char_traits::copy(buf, a.Data(), a.Length());
00105       }
00106 #endif
00107   }
00108 
00109 
00115 PRBool
00116 nsTSubstringTuple_CharT::IsDependentOn( const char_type *start, const char_type *end ) const
00117   {
00118     // we start with the right-most fragment since it is faster to check.
00119 
00120     if (TO_SUBSTRING(mFragB).IsDependentOn(start, end))
00121       return PR_TRUE;
00122 
00123     if (mHead)
00124       return mHead->IsDependentOn(start, end);
00125 
00126     return TO_SUBSTRING(mFragA).IsDependentOn(start, end);
00127   }