~ubuntu-branches/ubuntu/utopic/sysdig/utopic

« back to all changes in this revision

Viewing changes to userspace/libsinsp/utils.cpp

  • Committer: Package Import Robot
  • Author(s): Evgeni Golov
  • Date: 2014-05-01 14:53:09 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20140501145309-yy0hkts9nlu43omp
Tags: 0.1.81-1
* New upstream release
* Add B-D on zlib1g-dev and use it for building
* drop LuaJIT from debian/copyright, upstream does not ship the
  copy anymore
* Only require and execute dh_dkms when building arch-independent
  stuff

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
#include <limits.h>
22
22
#include <stdlib.h>
23
23
#endif
 
24
#include <algorithm> 
 
25
#include <functional> 
24
26
 
25
27
#include "sinsp.h"
26
28
#include "sinsp_int.h"
29
31
#include "filter.h"
30
32
#include "filterchecks.h"
31
33
 
 
34
#ifndef PATH_MAX
 
35
#define PATH_MAX 4096
 
36
#endif
 
37
 
32
38
#ifdef HAS_CHISELS
33
39
const chiseldir_info g_chisel_dirs_array[] =
34
40
{
652
658
        {
653
659
                ASSERT(false);
654
660
                strcpy(target, "/PATH_TOO_LONG");
 
661
                return false;
655
662
        }
656
663
 
657
664
        if(len2 != 0 && path2[0] != '/')
863
870
}
864
871
 
865
872
///////////////////////////////////////////////////////////////////////////////
 
873
// String helpers
 
874
///////////////////////////////////////////////////////////////////////////////
 
875
//
866
876
// String split
867
 
///////////////////////////////////////////////////////////////////////////////
 
877
//
868
878
vector<string> sinsp_split(const string &s, char delim)
869
879
{
870
880
    vector<string> res;
879
889
        return res;
880
890
}
881
891
 
 
892
//
 
893
// trim from start
 
894
//
 
895
string& ltrim(string &s) 
 
896
{
 
897
        s.erase(s.begin(), find_if(s.begin(), s.end(), not1(ptr_fun<int, int>(isspace))));
 
898
        return s;
 
899
}
 
900
 
 
901
//
 
902
// trim from end
 
903
//
 
904
string& rtrim(string &s) 
 
905
{
 
906
        s.erase(find_if(s.rbegin(), s.rend(), not1(ptr_fun<int, int>(isspace))).base(), s.end());
 
907
        return s;
 
908
}
 
909
 
 
910
//
 
911
// trim from both ends
 
912
//
 
913
string& trim(string &s) 
 
914
{
 
915
        return ltrim(rtrim(s));
 
916
}
 
917
 
 
918
void replace_in_place(string &s, const string &search, const string &replace)
 
919
{
 
920
        for(size_t pos = 0; ; pos += replace.length()) 
 
921
        {
 
922
                // Locate the substring to replace
 
923
                pos = s.find(search, pos);
 
924
                if(pos == string::npos ) break;
 
925
                // Replace by erasing and inserting
 
926
                s.erase(pos, search.length());
 
927
                s.insert(pos, replace );
 
928
        }
 
929
}
 
930
 
 
931
void replace_in_place(string& str, string& substr_to_replace, string& new_substr) 
 
932
{
 
933
        size_t index = 0;
 
934
        uint32_t nsize = substr_to_replace.size();
 
935
 
 
936
        while (true) 
 
937
        {
 
938
                 index = str.find(substr_to_replace, index);
 
939
                 if (index == string::npos) break;
 
940
 
 
941
                 str.replace(index, nsize, new_substr);
 
942
 
 
943
                 index += nsize;
 
944
        }
 
945
}
 
946
 
882
947
///////////////////////////////////////////////////////////////////////////////
883
948
// sinsp_numparser implementation
884
949
///////////////////////////////////////////////////////////////////////////////