On 10/10/2013 10:12 p.m., Amos Jeffries wrote:
This patch implements Alex's suggestion for step 1 of String removal by ...

Replace String class internals with an SBuf.

This method allows all String code to be converted quickly to SBuf without so much worry about correct API conversion elsewhere around the code since the wrapper provides exemplar cut-n-paste code to work from.

Addition of a SBuf constructor and toSBuf() accessor to String allows code using String to be converted directly to the SBuf API in smaller portions later. These obsolete the SBuf API converters to String and help reduce the SBuf API.

Updated patch following Kinkies audit and subsequent run-time testing. Since that earlier patch we have made the String class a lot more self-referential and re-added a few bugs which were in String behaviour.

Note to Alex:
Please audit this, but with a sole view of checking that the original String:: API semantics and behaviour are unchanged by the internals re-write. This patch seeks to *avoid* several things which would normally take up auditing time:
* fixing any bugs in the String API semantics or behaviour
* fixing any bugs in the code using String
* using correct C++ coding styles or patterns.

These bugs, behaviour and coding usage checks will be done on the following transition patches converting code variables from String to SBuf type.

Amos
=== modified file 'src/Makefile.am'
--- src/Makefile.am     2013-10-10 08:44:03 +0000
+++ src/Makefile.am     2013-10-10 09:31:51 +0000
@@ -15,21 +15,22 @@
        DnsLookupDetails.cc
 
 SBUF_SOURCE= \
        base/InstanceId.h \
        MemBlob.h \
        MemBlob.cc \
        OutOfBoundsException.h \
        SBuf.h \
        SBuf.cc \
        SBufExceptions.h \
-       SBufExceptions.cc
+       SBufExceptions.cc \
+       SquidString.h
 
 LOADABLE_MODULES_SOURCES = \
        LoadableModule.h \
        LoadableModule.cc \
        LoadableModules.h \
        LoadableModules.cc
 
 SUBDIRS        = base anyp comm eui acl format fs repl
 DIST_SUBDIRS = base anyp comm eui acl format fs repl
 
@@ -455,37 +456,36 @@
        peer_userhash.cc \
        PeerSelectState.h \
        PingData.h \
        protos.h \
        redirect.h \
        redirect.cc \
        refresh.h \
        refresh.cc \
        RemovalPolicy.cc \
        RemovalPolicy.h \
+       $(SBUF_SOURCE) \
        send-announce.h \
        send-announce.cc \
-       $(SBUF_SOURCE) \
        SBufStatsAction.h \
        SBufStatsAction.cc \
        $(SNMP_SOURCE) \
        SquidMath.h \
        SquidMath.cc \
        SquidNew.cc \
        IoStats.h \
        stat.h \
        stat.cc \
        StatCounters.h \
        StatCounters.cc \
        StatHist.h \
        StatHist.cc \
-       String.cc \
        StrList.h \
        StrList.cc \
        stmem.cc \
        stmem.h \
        repl_modules.h \
        store.cc \
        Store.h \
        StoreFileSystem.cc \
        StoreFileSystem.h \
        StoreHashIndex.h \
@@ -575,22 +575,20 @@
        $(UNLINKDSOURCE) \
        $(WIN32_ALL_SOURCE) \
        $(LOADABLE_MODULES_SOURCES)
 
 noinst_HEADERS = \
        client_side_request.cci \
        MemBuf.cci \
        MemBuf.h \
        Store.cci \
        StoreEntryStream.h \
-       String.cci \
-       SquidString.h \
        SquidTime.h
 
 BUILT_SOURCES = \
        cf_gen_defines.cci \
        cf_parser.cci \
        err_type.cc \
        err_detail_type.cc \
        globals.cc \
        hier_code.cc \
        icp_opcode.cc \
@@ -714,30 +712,30 @@
        cbdata.cc \
        debug.cc \
        int.h \
        int.cc \
        Mem.h \
        mem.cc \
        MemBuf.cc \
        MemBuf.cci \
        MemBuf.h \
        Parsing.h \
+       $(SBUF_SOURCE) \
        store_key_md5.h \
        store_key_md5.cc \
        StoreMeta.cc \
        StoreMetaMD5.cc \
        StoreMetaSTD.cc \
        StoreMetaSTDLFS.cc \
        StoreMetaUnpacker.cc \
        StoreMetaURL.cc \
        StoreMetaVary.cc \
-       String.cc \
        SquidNew.cc \
        time.cc \
        ufsdump.cc \
        dlink.h \
        dlink.cc \
        HelperChildConfig.h \
        tests/stub_HelperChildConfig.cc \
        HttpRequestMethod.cc \
        RemovalPolicy.cc \
        $(WIN32_SOURCE) \
@@ -1142,23 +1140,22 @@
        Mem.h \
        mem.cc \
        RegexList.h \
        RegexList.cc \
        MemBuf.cc \
        MemBuf.h \
        mime_header.h \
        mime_header.cc \
        Packer.cc \
        Packer.h \
-       SquidString.h \
+       $(SBUF_SOURCE) \
        SquidTime.h \
-       String.cc \
        StrList.h \
        StrList.cc \
        log/access_log.h \
        tests/stub_access_log.cc \
        cache_cf.h \
        YesNoNone.h \
        tests/stub_cache_cf.cc \
        tests/stub_cache_manager.cc \
        tests/stub_debug.cc \
        tests/stub_errorpage.cc \
@@ -1238,29 +1235,29 @@
        HttpRequestMethod.cc \
        int.h \
        int.cc \
        MasterXaction.cc \
        MasterXaction.h \
        SquidList.h \
        SquidList.cc \
        mem_node.cc \
        Packer.cc \
        Parsing.cc \
+       $(SBUF_SOURCE) \
        SquidMath.cc \
        StatCounters.cc \
        StatCounters.h \
        StatHist.h \
        StrList.h \
        StrList.cc \
        tests/stub_StatHist.cc \
        stmem.cc \
-       String.cc \
        store_dir.cc \
        StoreIOState.cc \
        StoreMeta.cc \
        StoreMetaMD5.cc \
        StoreMetaSTD.cc \
        StoreMetaSTDLFS.cc \
        StoreMetaUnpacker.cc \
        StoreMetaURL.cc \
        StoreMetaVary.cc \
        StoreSwapLogData.cc \
@@ -1371,21 +1368,21 @@
        $(ACL_REGISTRATION_SOURCES) \
        debug.cc \
        HttpParser.cc \
        HttpParser.h \
        RequestFlags.h \
        RequestFlags.cc \
        HttpRequest.cc \
        HttpRequestMethod.cc \
        Mem.h \
        mem.cc \
-       String.cc \
+       $(SBUF_SOURCE) \
        tests/testCacheManager.cc \
        tests/testCacheManager.h \
        tests/testMain.cc \
        tests/stub_main_cc.cc \
        tests/stub_ipc_Forwarder.cc \
        tests/stub_store_stats.cc \
        time.cc \
        BodyPipe.cc \
        cache_manager.cc \
        cache_cf.h \
@@ -1475,21 +1472,20 @@
        int.cc \
        internal.h \
        internal.cc \
        SquidList.h \
        SquidList.cc \
        MasterXaction.cc \
        MasterXaction.h \
        multicast.h \
        multicast.cc \
        mem_node.cc \
-       MemBlob.cc \
        MemBuf.cc \
        MemObject.cc \
        mime.h \
        mime.cc \
        mime_header.h \
        mime_header.cc \
        neighbors.h \
        neighbors.cc \
        Notes.cc \
        Notes.h \
@@ -1666,20 +1662,21 @@
        mem_node.cc \
        Mem.h \
        mem.cc \
        Packer.cc \
        Parsing.cc \
        refresh.h \
        refresh.cc \
        RemovalPolicy.cc \
        RequestFlags.h \
        RequestFlags.cc \
+       $(SBUF_SOURCE) \
        StatCounters.h \
        StatCounters.cc \
        StatHist.h \
        tests/stub_StatHist.cc \
        stmem.cc \
        StoreFileSystem.cc \
        StoreIOState.cc \
        StoreMeta.cc \
        StoreMetaMD5.cc \
        StoreMetaSTD.cc \
@@ -1689,21 +1686,20 @@
        StoreMetaVary.cc \
        StoreSwapLogData.cc \
        store_dir.cc \
        store_io.cc \
        store_key_md5.h \
        store_key_md5.cc \
        store_swapout.cc \
        store_swapmeta.cc \
        repl_modules.h \
        store.cc \
-       String.cc \
        StrList.h \
        StrList.cc \
        SwapDir.cc \
        log/access_log.h \
        tests/stub_access_log.cc \
        tests/stub_acl.cc \
        cache_cf.h \
        YesNoNone.h \
        tests/stub_cache_cf.cc \
        tests/stub_cache_manager.cc \
@@ -1895,21 +1891,20 @@
        int.cc \
        internal.h \
        internal.cc \
        SquidList.h \
        SquidList.cc \
        MasterXaction.cc \
        MasterXaction.h \
        Mem.h \
        mem.cc \
        mem_node.cc \
-       MemBlob.cc \
        MemBuf.cc \
        MemObject.cc \
        mime.h \
        mime.cc \
        mime_header.h \
        mime_header.cc \
        multicast.h \
        multicast.cc \
        neighbors.h \
        neighbors.cc \
@@ -1924,20 +1919,21 @@
        peer_select.cc \
        peer_sourcehash.h \
        peer_sourcehash.cc \
        peer_userhash.h \
        peer_userhash.cc \
        redirect.h \
        redirect.cc \
        refresh.h \
        refresh.cc \
        RemovalPolicy.cc \
+       $(SBUF_SOURCE) \
        Server.cc \
        StrList.h \
        StrList.cc \
        $(SNMP_SOURCE) \
        SquidMath.cc \
        SquidMath.h \
        IoStats.h \
        stat.h \
        stat.cc \
        StatCounters.h \
@@ -1965,21 +1961,20 @@
        StoreFileSystem.cc \
        StoreIOState.cc \
        StoreMeta.cc \
        StoreMetaMD5.cc \
        StoreMetaSTD.cc \
        StoreMetaSTDLFS.cc \
        StoreMetaUnpacker.cc \
        StoreMetaURL.cc \
        StoreMetaVary.cc \
        StoreSwapLogData.cc \
-       String.cc \
        SwapDir.cc \
        tests/CapturingStoreEntry.h \
        tests/testEvent.cc \
        tests/testEvent.h \
        tests/testMain.cc \
        tests/stub_main_cc.cc \
        tests/stub_ipc_Forwarder.cc \
        tests/stub_libeui.cc \
        tests/stub_store_stats.cc \
        time.cc \
@@ -2142,21 +2137,20 @@
        $(IPC_SOURCE) \
        ipcache.cc \
        int.h \
        int.cc \
        internal.h \
        internal.cc \
        SquidList.h \
        SquidList.cc \
        MasterXaction.cc \
        MasterXaction.h \
-       MemBlob.cc \
        MemBuf.cc \
        MemObject.cc \
        Mem.h \
        mem.cc \
        mem_node.cc \
        mime.h \
        mime.cc \
        mime_header.h \
        mime_header.cc \
        multicast.h \
@@ -2174,20 +2168,21 @@
        peer_select.cc \
        peer_sourcehash.h \
        peer_sourcehash.cc \
        peer_userhash.h \
        peer_userhash.cc \
        RemovalPolicy.cc \
        redirect.h \
        redirect.cc \
        refresh.h \
        refresh.cc \
+       $(SBUF_SOURCE) \
        Server.cc \
        $(SNMP_SOURCE) \
        SquidMath.h \
        SquidMath.cc \
        IoStats.h \
        stat.h \
        stat.cc \
        StatCounters.h \
        StatCounters.cc \
        StatHist.h \
@@ -2214,21 +2209,20 @@
        StoreFileSystem.cc \
        StoreIOState.cc \
        StoreMeta.cc \
        StoreMetaMD5.cc \
        StoreMetaSTD.cc \
        StoreMetaSTDLFS.cc \
        StoreMetaUnpacker.cc \
        StoreMetaURL.cc \
        StoreMetaVary.cc \
        StoreSwapLogData.cc \
-       String.cc \
        StrList.h \
        StrList.cc \
        SwapDir.cc \
        tests/testEventLoop.cc \
        tests/testEventLoop.h \
        tests/testMain.cc \
        tests/stub_main_cc.cc \
        tests/stub_ipc_Forwarder.cc \
        tests/stub_libeui.cc \
        tests/stub_store_stats.cc \
@@ -2389,21 +2383,20 @@
        int.h \
        int.cc \
        internal.h \
        internal.cc \
        $(IPC_SOURCE) \
        ipcache.cc \
        SquidList.h \
        SquidList.cc \
        MasterXaction.cc \
        MasterXaction.h \
-       MemBlob.cc \
        MemBuf.cc \
        MemObject.cc \
        Mem.h \
        mem.cc \
        mem_node.cc \
        mime.h \
        mime.cc \
        mime_header.h \
        mime_header.cc \
        multicast.h \
@@ -2421,20 +2414,21 @@
        peer_sourcehash.h \
        peer_sourcehash.cc \
        peer_userhash.h \
        peer_userhash.cc \
        pconn.cc \
        redirect.h \
        redirect.cc \
        refresh.h \
        refresh.cc \
        RemovalPolicy.cc \
+       $(SBUF_SOURCE) \
        Server.cc \
        $(SNMP_SOURCE) \
        SquidMath.h \
        SquidMath.cc \
        IoStats.h \
        stat.h \
        stat.cc \
        StatCounters.h \
        StatCounters.cc \
        StatHist.h \
@@ -2460,21 +2454,20 @@
        StoreFileSystem.cc \
        StoreIOState.cc \
        StoreMeta.cc \
        StoreMetaMD5.cc \
        StoreMetaSTD.cc \
        StoreMetaSTDLFS.cc \
        StoreMetaUnpacker.cc \
        StoreMetaURL.cc \
        StoreMetaVary.cc \
        StoreSwapLogData.cc \
-       String.cc \
        StrList.h \
        StrList.cc \
        SwapDir.cc \
        tests/test_http_range.cc \
        tests/stub_ipc_Forwarder.cc \
        tests/stub_libeui.cc \
        tests/stub_main_cc.cc \
        tests/stub_MemStore.cc \
        tests/stub_store_stats.cc \
        time.cc \
@@ -2537,21 +2530,21 @@
        $(SQUID_CPPUNIT_LA)
 
 tests_testHttpParser_SOURCES = \
        Debug.h \
        HttpParser.cc \
        HttpParser.h \
        MemBuf.cc \
        MemBuf.h \
        Mem.h \
        mem.cc \
-       String.cc \
+       $(SBUF_SOURCE) \
        cache_cf.h \
        YesNoNone.h \
        tests/stub_cache_cf.cc \
        tests/stub_cache_manager.cc \
        tests/stub_debug.cc \
        tests/stub_event.cc \
        tests/stub_HelperChildConfig.cc \
        tools.h \
        tests/stub_tools.cc \
        tests/testHttpParser.cc \
@@ -2580,21 +2573,21 @@
        AccessLogEntry.cc \
        $(ACL_REGISTRATION_SOURCES) \
        HttpParser.cc \
        HttpParser.h \
        RequestFlags.h \
        RequestFlags.cc \
        HttpRequest.cc \
        HttpRequestMethod.cc \
        Mem.h \
        mem.cc \
-       String.cc \
+       $(SBUF_SOURCE) \
        tests/testHttpRequest.h \
        tests/testHttpRequest.cc \
        tests/testHttpRequestMethod.h \
        tests/testHttpRequestMethod.cc \
        tests/testMain.cc \
        tests/stub_DiskIOModule.cc \
        tests/stub_main_cc.cc \
        tests/stub_ipc_Forwarder.cc \
        tests/stub_libeui.cc \
        tests/stub_store_stats.cc \
@@ -2684,21 +2677,20 @@
        int.cc \
        internal.h \
        internal.cc \
        SquidList.h \
        SquidList.cc \
        MasterXaction.cc \
        MasterXaction.h \
        multicast.h \
        multicast.cc \
        mem_node.cc \
-       MemBlob.cc \
        MemBuf.cc \
        MemObject.cc \
        mime.h \
        mime.cc \
        mime_header.h \
        mime_header.cc \
        neighbors.h \
        neighbors.cc \
        Notes.cc \
        Notes.h \
@@ -2866,20 +2858,21 @@
        Mem.h \
        mem.cc \
        mem_node.cc \
        MemBuf.cc \
        MemObject.cc \
        Packer.cc \
        Parsing.cc \
        RemovalPolicy.cc \
        refresh.h \
        refresh.cc \
+       $(SBUF_SOURCE) \
        StatCounters.h \
        StatCounters.cc \
        StatHist.h \
        StatHist.cc \
        stmem.cc \
        repl_modules.h \
        store.cc \
        store_dir.cc \
        store_io.cc \
        store_swapout.cc \
@@ -2887,21 +2880,20 @@
        StoreMeta.cc \
        StoreMetaMD5.cc \
        StoreMetaSTD.cc \
        StoreMetaSTDLFS.cc \
        StoreMetaUnpacker.cc \
        StoreMetaURL.cc \
        StoreMetaVary.cc \
        StoreSwapLogData.cc \
        store_key_md5.h \
        store_key_md5.cc \
-       String.cc \
        StrList.h \
        StrList.cc \
        SwapDir.cc \
        tests/CapturingStoreEntry.h \
        log/access_log.h \
        tests/stub_access_log.cc \
        tests/stub_acl.cc \
        cache_cf.h \
        YesNoNone.h \
        tests/stub_cache_cf.cc \
@@ -2992,21 +2984,21 @@
        $(SQUID_CPPUNIT_LA)
 
 ## string needs mem.cc.
 ## mem.cc needs ClientInfo.h
 ## libsquid pulls in SquidConfig and children. stub them.
 tests_testString_SOURCES = \
        ClientInfo.h \
        Mem.h \
        mem.cc \
        MemBuf.cc \
-       String.cc \
+       $(SBUF_SOURCE) \
        tests/testMain.cc \
        tests/testString.cc \
        tests/testString.h \
        cache_cf.h \
        YesNoNone.h \
        tests/stub_cache_cf.cc \
        tests/stub_cache_manager.cc \
        tests/stub_debug.cc \
        tests/stub_HelperChildConfig.cc \
        tools.h \
@@ -3079,20 +3071,21 @@
        disk.cc \
        FileMap.h \
        filemap.cc \
        HttpBody.h \
        HttpBody.cc \
        HttpReply.cc \
        int.h \
        int.cc \
        RequestFlags.h \
        RequestFlags.cc \
+       $(SBUF_SOURCE) \
        SquidList.h \
        SquidList.cc \
        MasterXaction.cc \
        MasterXaction.h \
        MemObject.cc \
        StoreSwapLogData.cc \
        StoreIOState.cc \
        StoreMeta.cc \
        StoreMetaMD5.cc \
        StoreMetaSTD.cc \
@@ -3122,21 +3115,20 @@
        store_key_md5.cc \
        Parsing.cc \
        ConfigOption.cc \
        SwapDir.cc \
        tests/stub_acl.cc \
        cache_cf.h \
        YesNoNone.h \
        tests/stub_cache_cf.cc \
        tests/stub_helper.cc \
        cbdata.cc \
-       String.cc \
        tests/stub_debug.cc \
        tests/stub_client_side_request.cc \
        tests/stub_http.cc \
        mem_node.cc \
        stmem.cc \
        mime.h \
        tests/stub_mime.cc \
        HttpHeaderFieldInfo.h \
        HttpHeaderTools.h \
        HttpHeaderTools.cc \
@@ -3281,20 +3273,21 @@
        Mem.h \
        mem.cc \
        MemBuf.cc \
        MemObject.cc \
        mem_node.cc \
        Packer.cc \
        Parsing.cc \
        RemovalPolicy.cc \
        RequestFlags.cc \
        RequestFlags.h \
+       $(SBUF_SOURCE) \
        StatCounters.h \
        StatCounters.cc \
        StatHist.h \
        tests/stub_StatHist.cc \
        stmem.cc \
        repl_modules.h \
        store.cc \
        StoreFileSystem.cc \
        StoreIOState.cc \
        StoreMeta.cc \
@@ -3304,21 +3297,20 @@
        StoreMetaURL.cc \
        StoreMetaUnpacker.cc \
        StoreMetaVary.cc \
        StoreSwapLogData.cc \
        store_dir.cc \
        store_io.cc \
        store_key_md5.h \
        store_key_md5.cc \
        store_swapmeta.cc \
        store_swapout.cc \
-       String.cc \
        StrList.h \
        StrList.cc \
        SwapDir.cc \
        tests/testRock.cc \
        tests/testMain.cc \
        tests/testRock.h \
        tests/testStoreSupport.cc \
        tests/testStoreSupport.h \
        log/access_log.h \
        tests/stub_access_log.cc \
@@ -3498,21 +3490,20 @@
        internal.cc \
        SquidList.h \
        SquidList.cc \
        MasterXaction.cc \
        MasterXaction.h \
        multicast.h \
        multicast.cc \
        Mem.h \
        mem.cc \
        mem_node.cc \
-       MemBlob.cc \
        MemBuf.cc \
        MemObject.cc \
        mime.h \
        mime.cc \
        mime_header.h \
        mime_header.cc \
        neighbors.h \
        neighbors.cc \
        Notes.cc \
        Notes.h \
@@ -3525,20 +3516,21 @@
        peer_select.cc \
        peer_sourcehash.h \
        peer_sourcehash.cc \
        peer_userhash.h \
        peer_userhash.cc \
        redirect.h \
        redirect.cc \
        refresh.h \
        refresh.cc \
        RemovalPolicy.cc \
+       $(SBUF_SOURCE) \
        Server.cc \
        $(SNMP_SOURCE) \
        SquidMath.h \
        SquidMath.cc \
        IoStats.h \
        stat.h \
        stat.cc \
        StatCounters.h \
        StatCounters.cc \
        StatHist.h \
@@ -3564,21 +3556,20 @@
        StoreFileSystem.cc \
        StoreIOState.cc \
        StoreMeta.cc \
        StoreMetaMD5.cc \
        StoreMetaSTD.cc \
        StoreMetaSTDLFS.cc \
        StoreMetaUnpacker.cc \
        StoreMetaURL.cc \
        StoreMetaVary.cc \
        StoreSwapLogData.cc \
-       String.cc \
        StrList.h \
        StrList.cc \
        SwapDir.cc \
        MemStore.cc \
        tests/stub_debug.cc \
        tests/stub_DiskIOModule.cc \
        tests/stub_main_cc.cc \
        tests/stub_ipc_Forwarder.cc \
        tests/stub_store_stats.cc \
        tests/testURL.cc \
@@ -3657,22 +3648,20 @@
        time.cc \
        mem.cc \
        tests/stub_debug.cc \
        tests/stub_fatal.cc \
        tests/stub_HelperChildConfig.cc \
        tests/stub_cache_cf.cc \
        tests/stub_cache_manager.cc \
        tests/stub_store.cc \
        tests/stub_store_stats.cc \
        tests/stub_tools.cc \
-       SquidString.h \
-       String.cc \
        wordlist.cc \
        MemBuf.cc
 nodist_tests_testSBuf_SOURCES=$(TESTSOURCES)
 tests_testSBuf_LDFLAGS = $(LIBADD_DL)
 tests_testSBuf_LDADD=\
        $(SQUID_CPPUNIT_LIBS) \
        $(SQUID_CPPUNIT_LA) \
        $(COMPAT_LIB) \
        libsquid.la \
        ip/libip.la \
@@ -3680,28 +3669,28 @@
        base/libbase.la \
        $(top_builddir)/lib/libmiscutil.la \
        $(COMMON_LIBS)
 tests_testSBuf_DEPENDENCIES= $(SQUID_CPPUNIT_LA)
 
 tests_testConfigParser_SOURCES = \
        ClientInfo.h \
        Mem.h \
        mem.cc \
        MemBuf.cc \
-       String.cc \
        ConfigParser.cc \
        fatal.h \
        tests/stub_fatal.cc \
        tests/testMain.cc \
        tests/testConfigParser.cc \
        tests/testConfigParser.h \
        cache_cf.h \
+       $(SBUF_SOURCE) \
        YesNoNone.h \
        tests/stub_cache_cf.cc \
        tests/stub_cache_manager.cc \
        tests/stub_debug.cc \
        tests/stub_HelperChildConfig.cc \
        tools.h \
        tests/stub_tools.cc \
        time.cc \
        wordlist.h \
        wordlist.cc
@@ -3721,34 +3710,34 @@
 tests_testConfigParser_DEPENDENCIES = \
        $(SQUID_CPPUNIT_LA)
        
 tests_testStatHist_SOURCES = \
        cbdata.cc \
        fatal.h \
        tests/stub_fatal.cc \
        MemBuf.cc \
        StatHist.cc \
        StatHist.h \
-       String.cc \
        tests/stub_cache_manager.cc \
        tests/stub_comm.cc \
        tests/stub_debug.cc \
        tests/stub_DelayId.cc \
        tests/stub_HelperChildConfig.cc \
        Mem.h \
        tests/stub_mem.cc \
        tests/stub_MemObject.cc \
        mime.h \
        tests/stub_mime.cc \
        tests/stub_pconn.cc \
        tests/stub_stmem.cc \
        repl_modules.h \
+       $(SBUF_SOURCE) \
        tests/stub_store.cc \
        tests/stub_store_stats.cc \
        tools.h \
        tests/stub_tools.cc \
        tests/testMain.cc \
        tests/testStatHist.cc \
        tests/testStatHist.h \
        time.cc
 nodist_tests_testStatHist_SOURCES = \
        $(TESTSOURCES)

=== modified file 'src/SBuf.cc'
--- src/SBuf.cc 2013-10-07 11:23:58 +0000
+++ src/SBuf.cc 2013-10-10 07:13:57 +0000
@@ -108,30 +108,20 @@
 
 SBuf::SBuf(const SBuf &S)
         : store_(S.store_), off_(S.off_), len_(S.len_)
 {
     debugs(24, 8, id << " created from id " << S.id);
     ++stats.alloc;
     ++stats.allocCopy;
     ++stats.live;
 }
 
-SBuf::SBuf(const String &S)
-        : store_(GetStorePrototype()), off_(0), len_(0)
-{
-    debugs(24, 8, id << " created from string");
-    assign(S.rawBuf(), S.size());
-    ++stats.alloc;
-    ++stats.allocFromString;
-    ++stats.live;
-}
-
 SBuf::SBuf(const std::string &s)
         : store_(GetStorePrototype()), off_(0), len_(0)
 {
     debugs(24, 8, id << " created from std::string");
     lowAppend(s.data(),s.length());
     ++stats.alloc;
     ++stats.allocFromString;
     ++stats.live;
 }
 
@@ -731,21 +721,21 @@
     return rv;
 }
 
 std::ostream &
 SBufStats::dump(std::ostream& os) const
 {
     MemBlobStats ststats = MemBlob::GetStats();
     os <<
     "SBuf stats:\nnumber of allocations: " << alloc <<
     "\ncopy-allocations: " << allocCopy <<
-    "\ncopy-allocations from SquidString: " << allocFromString <<
+    "\ncopy-allocations from std::string: " << allocFromString <<
     "\ncopy-allocations from C String: " << allocFromCString <<
     "\nlive references: " << live <<
     "\nno-copy assignments: " << assignFast <<
     "\nclearing operations: " << clear <<
     "\nappend operations: " << append <<
     "\ndump-to-ostream: " << toStream <<
     "\nset-char: " << setChar <<
     "\nget-char: " << getChar <<
     "\ncomparisons with data-scan: " << compareSlow <<
     "\ncomparisons not requiring data-scan: " << compareFast <<
@@ -798,29 +788,20 @@
  * checks whether the requested 'pos' is within the bounds of the SBuf
  * \throw OutOfBoundsException if access is out of bounds
  */
 void
 SBuf::checkAccessBounds(size_type pos) const
 {
     if (pos >= length())
         throw OutOfBoundsException(*this, pos, __FILE__, __LINE__);
 }
 
-String
-SBuf::toString() const
-{
-    String rv;
-    rv.limitInit(buf(), length());
-    ++stats.copyOut;
-    return rv;
-}
-
 /** re-allocate the backing store of the SBuf.
  *
  * If there are contents in the SBuf, they will be copied over.
  * NO verifications are made on the size parameters, it's up to the caller to
  * make sure that the new size is big enough to hold the copied contents.
  * The re-allocated storage MAY be bigger than the requested size due to 
size-chunking
  * algorithms in MemBlock, it is guarranteed NOT to be smaller.
  */
 void
 SBuf::reAlloc(size_type newsize)

=== modified file 'src/SBuf.h'
--- src/SBuf.h  2013-10-08 04:17:17 +0000
+++ src/SBuf.h  2013-10-12 04:45:38 +0000
@@ -25,21 +25,20 @@
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
  */
 
 #ifndef SQUID_SBUF_H
 #define SQUID_SBUF_H
 
 #include "base/InstanceId.h"
 #include "MemBlob.h"
 #include "SBufExceptions.h"
-#include "SquidString.h"
 
 #if HAVE_CLIMITS
 #include <climits>
 #elif HAVE_LIMITS_H
 #include <limits.h>
 #endif
 #if HAVE_UNISTD_H
 #include <unistd.h>
 #endif
 #if HAVE_STDARG_H
@@ -124,26 +123,20 @@
      * Create a new SBuf containing a COPY of the contents of the
      * c-string
      * \param S the c string to be copied
      * \param n how many bytes to import into the SBuf. If it is npos
      *              or unspecified, imports to end-of-cstring
      * \note it is the caller's responsibility not to go out of bounds
      * \note bounds is 0 <= pos < length(); caller must pay attention to 
signedness
      */
     explicit SBuf(const char *S, size_type n = npos);
 
-    /** Constructor: import SquidString, copying contents.
-     *
-     * This method will be removed once SquidString has gone.
-     */
-    explicit SBuf(const String &S);
-
     /// Constructor: import std::string. Contents are copied.
     explicit SBuf(const std::string &s);
 
     ~SBuf();
 
     /** Explicit assignment.
      *
      * Current SBuf will share backing store with the assigned one.
      */
     SBuf& assign(const SBuf &S);
@@ -303,21 +296,21 @@
      *
      * Export a copy of the SBuf's contents into the user-supplied
      * buffer, up to the user-supplied-length. No zero-termination is performed
      * \return num the number of actually-copied chars.
      */
     size_type copy(char *dest, size_type n) const;
 
     /** exports a pointer to the SBuf internal storage.
      * \warning ACCESSING RAW STORAGE IS DANGEROUS!
      *
-     * Returns a ead-only pointer to SBuf's content. No terminating null
+     * Returns a read-only pointer to SBuf's content. No terminating null
      * character is appended (use c_str() for that).
      * The returned value points to an internal location whose contents
      * are guaranteed to remain unchanged only until the next call
      * to a non-constant member function of the SBuf object. Such a
      * call may be implicit (e.g., when SBuf is destroyed
      * upon leaving the current context).
      * This is a very UNSAFE way of accessing the data.
      * This call never returns NULL.
      * \see c_str
      * \note the memory management system guarantees that the exported region
@@ -529,26 +522,20 @@
      */
     SBuf toLower() const;
 
     /** Upper-case SBuf
      *
      * Returns an upper-cased COPY of the SBuf
      * \see man toupper(3)
      */
     SBuf toUpper() const;
 
-    /** String export function
-     * converts the SBuf to a legacy String, by copy.
-     * \deprecated
-     */
-    String toString() const;
-
     /// std::string export function
     std::string toStdString() const { return std::string(buf(),length()); }
 
     // TODO: possibly implement erase() similar to std::string's erase
     // TODO: possibly implement a replace() call
 private:
 
     MemBlob::Pointer store_; ///< memory block, possibly shared with other 
SBufs
     size_type off_; ///< our content start offset from the beginning of shared 
store_
     size_type len_; ///< number of our content bytes in shared store_

=== modified file 'src/SquidString.h'
--- src/SquidString.h   2013-10-04 13:55:21 +0000
+++ src/SquidString.h   2013-10-11 14:25:48 +0000
@@ -1,151 +1,305 @@
-/*
- * DEBUG: section 67    String
- * AUTHOR: Duane Wessels
- *
- * SQUID Web Proxy Cache          http://www.squid-cache.org/
- * ----------------------------------------------------------
- *
- *  Squid is the result of efforts by numerous individuals from
- *  the Internet community; see the CONTRIBUTORS file for full
- *  details.   Many organizations have provided support for Squid's
- *  development; see the SPONSORS file for full details.  Squid is
- *  Copyrighted (C) 2001 by the Regents of the University of
- *  California; see the COPYRIGHT file for full details.  Squid
- *  incorporates software developed and/or copyrighted by other
- *  sources; see the CREDITS file for full details.
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
- *
- */
-
 #ifndef SQUID_STRING_H
 #define SQUID_STRING_H
 
+#include "SBuf.h"
+
+#include <cstring>
 #if HAVE_OSTREAM
 #include <ostream>
 #endif
 
+#if HAVE_STDINT_H
+#include <stdint.h>
+#else /* HAVE_STDINT_H */
+#ifndef INT_MAX
+#define INT_MAX 1<<31 //hack but a safe bet
+#endif /* INT_MAX */
+#endif /* HAVE_STDINT_H */
+
 /* squid string placeholder (for printf) */
 #ifndef SQUIDSTRINGPH
 #define SQUIDSTRINGPH "%.*s"
 #define SQUIDSTRINGPRINT(s) (s).psize(),(s).rawBuf()
 #endif /* SQUIDSTRINGPH */
 
 class String
 {
-
 public:
-    _SQUID_INLINE_ String();
-    String(char const *);
-    String(String const &);
-    ~String();
-
-    typedef size_t size_type; //storage size intentionally unspecified
-    const static size_type npos = std::string::npos;
-
-    String &operator =(char const *);
-    String &operator =(String const &);
-    bool operator ==(String const &) const;
-    bool operator !=(String const &) const;
+    String() : buf_(), defined_(false) {}
+    String(char const *s) : buf_(s), defined_(s != NULL) {}
+    String(String const &s) : buf_(s.buf_), defined_(s.defined()) {}
+    String(SBuf const &s) : buf_(s), defined_(s.length() > 0) {}
+
+    typedef SBuf::size_type size_type; //storage size intentionally unspecified
+    const static size_type npos = SBuf::npos;
+
+    String &operator =(char const *s) {reset(s);return *this;}
+    String &operator =(String const &s) {
+        buf_.clear();
+        buf_=s.buf_;
+        defined_=s.defined_;
+        return *this;
+    }
+    String &operator =(SBuf s) {
+        defined_=true;
+        buf_=s;
+        return *this;
+    }
+    bool operator ==(String const &s) const {return defined() == s.defined() 
&& buf_ == s.buf_;}
+    bool operator !=(String const &s) const {return defined() != s.defined() 
|| buf_ != s.buf_;}
 
-    /**
-     * Retrieve a single character in the string.
-     \param pos        Position of character to retrieve.
-     */
-    _SQUID_INLINE_ char operator [](unsigned int pos) const;
+    char operator [](unsigned int p) const {return buf_[p];}
+
+    size_type size() const {return buf_.length();}
 
-    _SQUID_INLINE_ size_type size() const;
     /// variant of size() suited to be used for printf-alikes.
-    /// throws when size() > MAXINT
-    int psize() const;
+    /// throws when size() would overflow
+    int psize() const {
+        Must(buf_.length() < INT_MAX);
+        return buf_.length();
+    }
 
-    /**
-     * \retval true the String has some contents
-     */
-    _SQUID_INLINE_ bool defined() const;
-    /**
-     * \retval true the String does not hold any contents
-     */
-    _SQUID_INLINE_ bool undefined() const;
+    bool defined() const {return defined_;}
+    bool undefined() const {return !defined();}
     /**
      * Returns a raw pointer to the underlying backing store. The caller has 
been
      * verified not to make any assumptions about null-termination
      */
-    _SQUID_INLINE_ char const * rawBuf() const;
+    char const * rawBuf() const {return termedBuf();}
     /**
      * Returns a raw pointer to the underlying backing store.
      * The caller requires it to be null-terminated.
      */
-    _SQUID_INLINE_ char const * termedBuf() const;
-    void limitInit(const char *str, int len); // TODO: rename to assign()
-    void clean();
-    void reset(char const *str);
-    void append(char const *buf, int len);
-    void append(char const *buf);
-    void append(char const);
-    void append(String const &);
-    void absorb(String &old);
-    const char * pos(char const *aString) const;
-    const char * pos(char const ch) const;
+    char const * termedBuf() const {
+        if (!defined()) return NULL;
+        // XXX: callers will probably try and write to the buffer,
+        // but SquidString never offered any more guarantee than SBuf
+        // does now about buffers existence.
+        return buf_.c_str();
+    }
+    SBuf toSBuf() const {return buf_;}
+    void limitInit(const char *str, int len) {
+        clean();
+        append(str,len);
+    }
+    void clean() {
+        buf_.clear();
+        defined_=false;
+    }
+    void reset(char const *str) {
+        clean();
+        if (str!=NULL) {
+            append(str);
+            // XXX: empty string "" sent to append means no change,
+            // but on reset / assignment it means set a defined empty string.
+            defined_=true;
+        }
+    }
+    void append(char const *buf, int len) {
+        buf_.append(buf,len);
+        defined_|=(len > 0);
+    }
+    void append(char const *buf) {
+        assert(buf);
+        append(buf, strlen(buf));
+    }
+    void append(char const chr) {
+        char myString[2];
+        myString[0]=chr;
+        myString[1]='\0';
+        append(myString, 1);
+    }
+    void append(String const &s) {
+        buf_.append(s.buf_);
+        defined_|=s.defined();
+    }
+    void absorb(String &old) {
+        operator = (old);
+        old.clean();
+    }
+    const char * pos(char const *aString) const {
+        if (!defined())
+            return NULL;
+        return strstr(termedBuf(), aString);
+    }
+    const char * pos(char const ch) const {
+        if (!defined())
+            return NULL;
+        return strchr(termedBuf(), ch);
+    }
     ///offset from string start of the first occurrence of ch
     /// returns String::npos if ch is not found
-    size_type find(char const ch) const;
-    size_type find(char const *aString) const;
-    const char * rpos(char const ch) const;
-    size_type rfind(char const ch) const;
-    _SQUID_INLINE_ int cmp(char const *) const;
-    _SQUID_INLINE_ int cmp(char const *, size_type count) const;
-    _SQUID_INLINE_ int cmp(String const &) const;
-    _SQUID_INLINE_ int caseCmp(char const *) const;
-    _SQUID_INLINE_ int caseCmp(char const *, size_type count) const;
-    _SQUID_INLINE_ int caseCmp(String const &) const;
-
-    String substr(size_type from, size_type to) const;
-
-    _SQUID_INLINE_ void cut(size_type newLength);
+    size_type find(char const ch) const {
+        const char *c;
+        c=pos(ch);
+        if (c==NULL)
+            return npos;
+        return c-rawBuf();
+    }
+    size_type find(char const *aString) const {
+        const char *c=pos(aString);
+        if (c==NULL)
+            return npos;
+        return c-rawBuf();
+    }
+    const char * rpos(char const ch) const {
+        if (!defined())
+            return NULL;
+        return strrchr(termedBuf(), (ch));
+    }
+    size_type rfind(char const ch) const {
+        const char *c = rpos(ch);
+        if (c==NULL)
+            return npos;
+        return c-rawBuf();
+    }
+
+    int cmp(char const *s) const {return buf_.cmp(SBuf(s));}
+    int cmp(char const *s, size_type count) const {
+        // XXX: SquidString ignores the terminator. SBuf treats it as a byte.
+        if (s!=NULL && strlen(s) < count)
+            count = strlen(s);
+        return buf_.cmp(SBuf(s,count), count);
+    }
+    int cmp(String const &s) const {return buf_.cmp(s.buf_);}
+    int caseCmp(char const *s) const {return buf_.caseCmp(SBuf(s));}
+    int caseCmp(char const *s, size_type count) const {
+        // XXX: SquidString ignores the terminator. SBuf treats it as a byte.
+        if (s!=NULL && strlen(s) < count)
+            count = strlen(s);
+        return buf_.caseCmp(SBuf(s,count), count);
+    }
+    int caseCmp(String const &s) const {return buf_.caseCmp(s.buf_);}
+
+    String substr(size_type from, size_type to) const {
+        Must(from < buf_.length());
+        Must(to > 0 && to <= buf_.length());
+        Must(to > from);
+        return String(buf_.substr(from, to-from));
+    }
+
+    void cut(size_type newLength) {
+        if (newLength > buf_.length()) return;
+        if (buf_.length() == 0 && !defined()) return;
+        buf_.setAt(newLength, '\0');
+        buf_.chop(newLength);
+    }
 
 private:
-    void allocAndFill(const char *str, int len);
-    void allocBuffer(size_type sz);
-    void setBuffer(char *buf, size_type sz);
-
-    _SQUID_INLINE_ bool nilCmp(bool, bool, int &) const;
-
-    /* never reference these directly! */
-    size_type size_; /* buffer size; 64K limit */
-
-    size_type len_;  /* current length  */
-
-    char *buf_;
-
-    _SQUID_INLINE_ void set(char const *loc, char const ch);
-    _SQUID_INLINE_ void cutPointer(char const *loc);
+    mutable SBuf buf_;
 
+    // SquidString used to track whether buf_ was NULL or not
+    // and some code makes use of this property.
+    // Until that is all checked and defined()/undefined() erased
+    // we explicitly track whether SquidString would have had
+    // buf_ allocated.
+    mutable bool defined_;
 };
 
-_SQUID_INLINE_ std::ostream & operator<<(std::ostream& os, String const 
&aString);
-
-_SQUID_INLINE_ bool operator<(const String &a, const String &b);
-
-#if _USE_INLINE_
-#include "String.cci"
-#endif
+inline std::ostream & operator<<(std::ostream& os, String const &aString) {
+    return os << aString.toSBuf();
+}
+
+inline bool operator<(const String &a, const String &b) {
+    return a.toSBuf().cmp(b.toSBuf()) < 0;
+}
+
+inline const char *checkNullString(const char *p) {
+    return p ? p : "(NULL)";
+}
+
+inline int stringHasWhitespace(const char *s) {
+    return strpbrk(s, w_space) != NULL;
+}
+
+inline int stringHasCntl(const char *s) {
+    unsigned char c;
+    while ((c = (unsigned char) *s++) != '\0') {
+        if (c <= 0x1f)
+            return 1;
+        if (c >= 0x7f && c <= 0x9f)
+            return 1;
+    }
+    return 0;
+}
 
-const char *checkNullString(const char *p);
-int stringHasWhitespace(const char *);
-int stringHasCntl(const char *);
-char *strwordtok(char *buf, char **t);
+/*
+ * Similar to strtok, but has some rudimentary knowledge
+ * of quoting
+ */
+inline char *strwordtok(char *buf, char **t) {
+    unsigned char *word = NULL;
+    unsigned char *p = (unsigned char *) buf;
+    unsigned char *d;
+    unsigned char ch;
+    bool quoted = false;
+
+    if (!p)
+        p = (unsigned char *) *t;
+
+    if (!p) {
+        *t = (char *) p;
+        return (char *) word;
+    }
+
+    while (*p && xisspace(*p))
+        ++p;
+
+    if (!*p) {
+        *t = (char *) p;
+        return (char *) word;
+    }
+
+    word = d = p;
+
+    while ((ch = *p)) {
+        switch (ch) {
+
+        case '\\':
+            ++p;
+
+            switch (*p) {
+            case 'n':
+                ch = '\n';
+                break;
+            case 'r':
+                ch = '\r';
+                break;
+            default:
+                ch = *p;
+                break;
+            }
+
+            *d = ch;
+            ++d;
+
+            if (ch)
+                ++p;
+            break;
+
+        case '"':
+            quoted = !quoted;
+            ++p;
+            break;
+
+        default:
+            if (!quoted && xisspace(*p)) {
+                ++p;
+                *d = '\0';
+                *t = (char *) p;
+                return (char *) word;
+            }
+
+            *d = *p;
+            ++d;
+            ++p;
+            break;
+        }
+    }
+
+    *d = '\0';
+    *t = (char *) p;
+    return (char *) word;
+}
 
 #endif /* SQUID_STRING_H */

=== removed file 'src/String.cc'
--- src/String.cc       2012-10-04 09:14:06 +0000
+++ src/String.cc       1970-01-01 00:00:00 +0000
@@ -1,498 +0,0 @@
-
-/*
- * DEBUG: section 67    String
- * AUTHOR: Duane Wessels
- *
- * SQUID Web Proxy Cache          http://www.squid-cache.org/
- * ----------------------------------------------------------
- *
- *  Squid is the result of efforts by numerous individuals from
- *  the Internet community; see the CONTRIBUTORS file for full
- *  details.   Many organizations have provided support for Squid's
- *  development; see the SPONSORS file for full details.  Squid is
- *  Copyrighted (C) 2001 by the Regents of the University of
- *  California; see the COPYRIGHT file for full details.  Squid
- *  incorporates software developed and/or copyrighted by other
- *  sources; see the CREDITS file for full details.
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
- *
- */
-
-#include "squid.h"
-#include "base/TextException.h"
-#include "Mem.h"
-#include "mgr/Registration.h"
-#include "profiler/Profiler.h"
-#include "Store.h"
-
-#if HAVE_LIMITS_H
-#include <limits.h>
-#endif
-
-int
-String::psize() const
-{
-    Must(size() < INT_MAX);
-    return size();
-}
-
-// low-level buffer allocation,
-// does not free old buffer and does not adjust or look at len_
-void
-String::allocBuffer(String::size_type sz)
-{
-    PROF_start(StringInitBuf);
-    assert (undefined());
-    char *newBuffer = (char*)memAllocString(sz, &sz);
-    setBuffer(newBuffer, sz);
-    PROF_stop(StringInitBuf);
-}
-
-// low-level buffer assignment
-// does not free old buffer and does not adjust or look at len_
-void
-String::setBuffer(char *aBuf, String::size_type aSize)
-{
-    assert(undefined());
-    assert(aSize < 65536);
-    buf_ = aBuf;
-    size_ = aSize;
-}
-
-String::String(char const *aString) : size_(0), len_(0), buf_(NULL)
-{
-    if (aString)
-        allocAndFill(aString, strlen(aString));
-#if DEBUGSTRINGS
-
-    StringRegistry::Instance().add(this);
-#endif
-}
-
-String &
-String::operator =(char const *aString)
-{
-    reset(aString);
-    return *this;
-}
-
-String &
-String::operator =(String const &old)
-{
-    clean(); // TODO: optimize to avoid cleaning the buffer we can use
-    if (old.size() > 0)
-        allocAndFill(old.rawBuf(), old.size());
-    return *this;
-}
-
-bool
-String::operator ==(String const &that) const
-{
-    if (0 == this->cmp(that))
-        return true;
-
-    return false;
-}
-
-bool
-String::operator !=(String const &that) const
-{
-    if (0 == this->cmp(that))
-        return false;
-
-    return true;
-}
-
-// public interface, makes sure that we clean the old buffer first
-void
-String::limitInit(const char *str, int len)
-{
-    clean(); // TODO: optimize to avoid cleaning the buffer we can use
-    allocAndFill(str, len);
-}
-
-// Allocates the buffer to fit the supplied string and fills it.
-// Does not clean.
-void
-String::allocAndFill(const char *str, int len)
-{
-    PROF_start(StringAllocAndFill);
-    assert(this && str);
-    allocBuffer(len + 1);
-    len_ = len;
-    memcpy(buf_, str, len);
-    buf_[len] = '\0';
-    PROF_stop(StringAllocAndFill);
-}
-
-String::String(String const &old) : size_(0), len_(0), buf_(NULL)
-{
-    if (old.size() > 0)
-        allocAndFill(old.rawBuf(), old.size());
-#if DEBUGSTRINGS
-
-    StringRegistry::Instance().add(this);
-#endif
-}
-
-void
-String::clean()
-{
-    PROF_start(StringClean);
-    assert(this);
-
-    /* TODO if mempools has already closed this will FAIL!! */
-    if (defined())
-        memFreeString(size_, buf_);
-
-    len_ = 0;
-
-    size_ = 0;
-
-    buf_ = NULL;
-    PROF_stop(StringClean);
-}
-
-String::~String()
-{
-    clean();
-#if DEBUGSTRINGS
-
-    StringRegistry::Instance().remove(this);
-#endif
-}
-
-void
-String::reset(char const *str)
-{
-    PROF_start(StringReset);
-    clean(); // TODO: optimize to avoid cleaning the buffer if we can reuse it
-    if (str)
-        allocAndFill(str, strlen(str));
-    PROF_stop(StringReset);
-}
-
-void
-String::append( char const *str, int len)
-{
-    assert(this);
-    assert(str && len >= 0);
-
-    PROF_start(StringAppend);
-    if (len_ + len < size_) {
-        strncat(buf_, str, len);
-        len_ += len;
-    } else {
-        // Create a temporary string and absorb it later.
-        String snew;
-        assert(len_ + len < 65536); // otherwise snew.len_ overflows below
-        snew.len_ = len_ + len;
-        snew.allocBuffer(snew.len_ + 1);
-
-        if (len_)
-            memcpy(snew.buf_, rawBuf(), len_);
-
-        if (len)
-            memcpy(snew.buf_ + len_, str, len);
-
-        snew.buf_[snew.len_] = '\0';
-
-        absorb(snew);
-    }
-    PROF_stop(StringAppend);
-}
-
-void
-String::append(char const *str)
-{
-    assert(str);
-    append(str, strlen(str));
-}
-
-void
-String::append(char const chr)
-{
-    char myString[2];
-    myString[0]=chr;
-    myString[1]='\0';
-    append(myString, 1);
-}
-
-void
-String::append(String const &old)
-{
-    append(old.rawBuf(), old.len_);
-}
-
-void
-String::absorb(String &old)
-{
-    clean();
-    setBuffer(old.buf_, old.size_);
-    len_ = old.len_;
-    old.size_ = 0;
-    old.buf_ = NULL;
-    old.len_ = 0;
-}
-
-String
-String::substr(String::size_type from, String::size_type to) const
-{
-//    Must(from >= 0 && from < size());
-    Must(from < size());
-    Must(to > 0 && to <= size());
-    Must(to > from);
-
-    String rv;
-    rv.limitInit(rawBuf()+from,to-from);
-    return rv;
-}
-
-#if DEBUGSTRINGS
-void
-String::stat(StoreEntry *entry) const
-{
-    storeAppendPrintf(entry, "%p : %d/%d \"%.*s\"\n",this,len_, size_, size(), 
rawBuf());
-}
-
-StringRegistry &
-StringRegistry::Instance()
-{
-    return Instance_;
-}
-
-template <class C>
-int
-ptrcmp(C const &lhs, C const &rhs)
-{
-    return lhs - rhs;
-}
-
-StringRegistry::StringRegistry()
-{
-#if DEBUGSTRINGS
-    Mgr::RegisterAction("strings",
-                        "Strings in use in squid", Stat, 0, 1);
-#endif
-}
-
-void
-StringRegistry::add(String const *entry)
-{
-    entries.insert(entry, ptrcmp);
-}
-
-void
-StringRegistry::remove(String const *entry)
-{
-    entries.remove(entry, ptrcmp);
-}
-
-StringRegistry StringRegistry::Instance_;
-
-String::size_type memStringCount();
-
-void
-StringRegistry::Stat(StoreEntry *entry)
-{
-    storeAppendPrintf(entry, "%lu entries, %lu reported from MemPool\n", 
(unsigned long) Instance().entries.elements, (unsigned long) memStringCount());
-    Instance().entries.head->walk(Stater, entry);
-}
-
-void
-StringRegistry::Stater(String const * const & nodedata, void *state)
-{
-    StoreEntry *entry = (StoreEntry *) state;
-    nodedata->stat(entry);
-}
-
-#endif
-
-/* TODO: move onto String */
-int
-stringHasWhitespace(const char *s)
-{
-    return strpbrk(s, w_space) != NULL;
-}
-
-/* TODO: move onto String */
-int
-stringHasCntl(const char *s)
-{
-    unsigned char c;
-
-    while ((c = (unsigned char) *s++) != '\0') {
-        if (c <= 0x1f)
-            return 1;
-
-        if (c >= 0x7f && c <= 0x9f)
-            return 1;
-    }
-
-    return 0;
-}
-
-/*
- * Similar to strtok, but has some rudimentary knowledge
- * of quoting
- */
-char *
-strwordtok(char *buf, char **t)
-{
-    unsigned char *word = NULL;
-    unsigned char *p = (unsigned char *) buf;
-    unsigned char *d;
-    unsigned char ch;
-    int quoted = 0;
-
-    if (!p)
-        p = (unsigned char *) *t;
-
-    if (!p)
-        goto error;
-
-    while (*p && xisspace(*p))
-        ++p;
-
-    if (!*p)
-        goto error;
-
-    word = d = p;
-
-    while ((ch = *p)) {
-        switch (ch) {
-
-        case '\\':
-            ++p;
-
-            switch (*p) {
-
-            case 'n':
-                ch = '\n';
-
-                break;
-
-            case 'r':
-                ch = '\r';
-
-                break;
-
-            default:
-                ch = *p;
-
-                break;
-
-            }
-
-            *d = ch;
-            ++d;
-
-            if (ch)
-                ++p;
-
-            break;
-
-        case '"':
-            quoted = !quoted;
-
-            ++p;
-
-            break;
-
-        default:
-            if (!quoted && xisspace(*p)) {
-                ++p;
-                goto done;
-            }
-
-            *d = *p;
-            ++d;
-            ++p;
-            break;
-        }
-    }
-
-done:
-    *d = '\0';
-
-error:
-    *t = (char *) p;
-    return (char *) word;
-}
-
-const char *
-checkNullString(const char *p)
-{
-    return p ? p : "(NULL)";
-}
-
-const char *
-String::pos(char const *aString) const
-{
-    if (undefined())
-        return NULL;
-    return strstr(termedBuf(), aString);
-}
-
-const char *
-String::pos(char const ch) const
-{
-    if (undefined())
-        return NULL;
-    return strchr(termedBuf(), ch);
-}
-
-const char *
-String::rpos(char const ch) const
-{
-    if (undefined())
-        return NULL;
-    return strrchr(termedBuf(), (ch));
-}
-
-String::size_type
-String::find(char const ch) const
-{
-    const char *c;
-    c=pos(ch);
-    if (c==NULL)
-        return npos;
-    return c-rawBuf();
-}
-
-String::size_type
-String::find(char const *aString) const
-{
-    const char *c;
-    c=pos(aString);
-    if (c==NULL)
-        return npos;
-    return c-rawBuf();
-}
-
-String::size_type
-String::rfind(char const ch) const
-{
-    const char *c;
-    c=rpos(ch);
-    if (c==NULL)
-        return npos;
-    return c-rawBuf();
-}
-
-#if !_USE_INLINE_
-#include "String.cci"
-#endif

=== removed file 'src/String.cci'
--- src/String.cci      2012-09-22 01:28:35 +0000
+++ src/String.cci      1970-01-01 00:00:00 +0000
@@ -1,202 +0,0 @@
-/*
- * DEBUG: section 67    String
- * AUTHOR: Duane Wessels
- *
- * SQUID Web Proxy Cache          http://www.squid-cache.org/
- * ----------------------------------------------------------
- *
- *  Squid is the result of efforts by numerous individuals from
- *  the Internet community; see the CONTRIBUTORS file for full
- *  details.   Many organizations have provided support for Squid's
- *  development; see the SPONSORS file for full details.  Squid is
- *  Copyrighted (C) 2001 by the Regents of the University of
- *  California; see the COPYRIGHT file for full details.  Squid
- *  incorporates software developed and/or copyrighted by other
- *  sources; see the CREDITS file for full details.
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
- *
- */
-
-#include <cstring>
-
-#if HAVE_STDINT_H
-#include <stdint.h>
-#else /* HAVE_STDINT_H */
-#ifndef INT_MAX
-#define INT_MAX 1<<31 //hack but a safe bet
-#endif /* INT_MAX */
-#endif /* HAVE_STDINT_H */
-
-String::String() : size_(0), len_(0), buf_(NULL)
-{
-#if DEBUGSTRINGS
-    StringRegistry::Instance().add(this);
-#endif
-}
-
-String::size_type
-String::size() const
-{
-    return len_;
-}
-
-bool String::defined() const
-{
-    return buf_!=NULL;
-}
-
-bool String::undefined() const
-{
-    return buf_==NULL;
-}
-
-char const *
-String::rawBuf() const
-{
-    return buf_;
-}
-
-char const *
-String::termedBuf() const
-{
-    return buf_;
-}
-
-char
-String::operator [](unsigned int aPos) const
-{
-    assert(aPos < size_);
-
-    return buf_[aPos];
-}
-
-/// compare NULL and empty strings because str*cmp() may fail on NULL strings
-/// and because we need to return consistent results for strncmp(count == 0).
-bool
-String::nilCmp(const bool thisIsNilOrEmpty, const bool otherIsNilOrEmpty, int 
&result) const
-{
-    if (!thisIsNilOrEmpty && !otherIsNilOrEmpty)
-        return false; // result does not matter
-
-    if (thisIsNilOrEmpty && otherIsNilOrEmpty)
-        result = 0;
-    else if (thisIsNilOrEmpty)
-        result = -1;
-    else // otherIsNilOrEmpty
-        result = +1;
-
-    return true;
-}
-
-int
-String::cmp(char const *aString) const
-{
-    int result = 0;
-    if (nilCmp(!size(), (!aString || !*aString), result))
-        return result;
-
-    return strcmp(termedBuf(), aString);
-}
-
-int
-String::cmp(char const *aString, String::size_type count) const
-{
-    int result = 0;
-    if (nilCmp((!size() || !count), (!aString || !*aString || !count), result))
-        return result;
-
-    return strncmp(termedBuf(), aString, count);
-}
-
-int
-String::cmp(String const &aString) const
-{
-    int result = 0;
-    if (nilCmp(!size(), !aString.size(), result))
-        return result;
-
-    return strcmp(termedBuf(), aString.termedBuf());
-}
-
-int
-String::caseCmp(char const *aString) const
-{
-    int result = 0;
-    if (nilCmp(!size(), (!aString || !*aString), result))
-        return result;
-
-    return strcasecmp(termedBuf(), aString);
-}
-
-int
-String::caseCmp(char const *aString, String::size_type count) const
-{
-    int result = 0;
-    if (nilCmp((!size() || !count), (!aString || !*aString || !count), result))
-        return result;
-
-    return strncasecmp(termedBuf(), aString, count);
-}
-
-int
-String::caseCmp(const String &str) const
-{
-    return caseCmp(str.rawBuf(),str.size());
-}
-
-void
-String::set(char const *loc, char const ch)
-{
-    if (loc < buf_ || loc > (buf_ + size_) ) return;
-
-    buf_[loc-buf_] = ch;
-}
-
-void
-String::cut(String::size_type newLength)
-{
-    // size_type is size_t, unsigned. No need to check for newLength <0
-    if (newLength > len_) return;
-
-    len_ = newLength;
-
-    // buf_ may be NULL on zero-length strings.
-    if (len_ == 0 && buf_ == NULL) return;
-
-    buf_[newLength] = '\0';
-}
-
-void
-String::cutPointer(char const *loc)
-{
-    if (loc < buf_ || loc > (buf_ + size_) ) return;
-
-    len_ = loc-buf_;
-    buf_[len_] = '\0';
-}
-
-std::ostream &
-operator<<(std::ostream& os, String const &aString)
-{
-    os.write(aString.rawBuf(),aString.size());
-    return os;
-}
-
-bool
-operator<(const String &a, const String &b)
-{
-    return a.cmp(b) < 0;
-}

=== modified file 'src/tests/testSBuf.cc'
--- src/tests/testSBuf.cc       2013-10-07 10:23:48 +0000
+++ src/tests/testSBuf.cc       2013-10-10 07:21:28 +0000
@@ -98,27 +98,20 @@
     // TEST: sub-string copy
     {
         SBuf s1=SBuf(fox+4), s2(fox);
         SBuf s3=s2.substr(4,s2.length()); //n is out-of-bounds
         CPPUNIT_ASSERT_EQUAL(s1,s3);
         SBuf s4=SBuf(fox,4);
         s3=s2.substr(0,4);
         CPPUNIT_ASSERT_EQUAL(s4,s3);
     }
 
-    // TEST: go via SquidString adapters.
-    {
-        String str(fox);
-        SBuf s1(str);
-        CPPUNIT_ASSERT_EQUAL(literal,s1);
-    }
-
     // TEST: go via std::string adapter.
     {
         std::string str(fox);
         SBuf s1(str);
         CPPUNIT_ASSERT_EQUAL(literal,s1);
     }
 }
 
 void
 testSBuf::testSBufConstructDestructAfterMemInit()

Reply via email to