当前位置: 首页>>代码示例>>C++>>正文


C++ MyString::size方法代码示例

本文整理汇总了C++中MyString::size方法的典型用法代码示例。如果您正苦于以下问题:C++ MyString::size方法的具体用法?C++ MyString::size怎么用?C++ MyString::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MyString的用法示例。


在下文中一共展示了MyString::size方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: myStringToInt

	//convert MyString to int noexcept
	int myStringToInt(const MyString& str)
	{
		if (str.size() == 0)
			return 0;
		int res = 0;
		if (str[0] == '-')
		{
			int sign(-1);
			int mnog(1);
			for (int i = str.size() - 1; i != 0; i--)
			{
				res =res + mnog*((int)str[i] - '0');
				mnog *= 10;
			}
			res *= sign;
		}
		else
		{
			int mnog(1);
			for (int i = str.size() - 1; i != -1; i--)
			{
				res = res + mnog*(str[i] - '0');
				mnog *= 10;
			}
		}
		return res;
	}
开发者ID:qqingvarqq,项目名称:universitu_second_course_programming_source_code,代码行数:28,代码来源:MyString.cpp

示例2: name

Vector<MyString> split(const MyString& path)
{
    Vector<MyString> ret;
    int spos = 0;
    while (spos < path.size())
    {
        int epos = path.find(_T('\\'), spos);
        if (epos != -1)
        {
            int i = epos + 1;
            while (i < path.size() && path[i] == _T('\\'))
                ++i;
            MyString name(path.substr(spos, epos - spos));
            ret.append(name);
            spos = i;
        }
        else if (spos < path.size())
        {
            MyString name(path.substr(spos));
            ret.append(name);
            spos = path.size();
        }
    }
    return ret;
}
开发者ID:unoyx,项目名称:vfs,代码行数:25,代码来源:path.cpp

示例3: getPath

static int getPath(const MyString& cmd, int pos, MyString* p)
{
    int i = pos;
    while (i < cmd.size() && _istspace(cmd[i]))
        ++i;
    int j = i;
    // 处理以双引号包括的路径
    if (cmd[j] == _T('"'))
    {
        ++j;
        while (j < cmd.size() && cmd[j] != _T('"'))
            ++j;
        if (j == cmd.size())
        {
            return -1;
        }
        else
        {
            *p = cmd.substr(i + 1, j - i - 1);
            return j + 1;
        }
    }
    else
    {
        while (j < cmd.size() 
            && !_istspace(cmd[j])
            && cmd[j] != _T('/'))
            ++j;
        *p = cmd.substr(i, j - i);
        return j;
    }
}
开发者ID:unoyx,项目名称:vfs,代码行数:32,代码来源:CommandParser.cpp

示例4:

bool operator==(const MyString& lhs, const MyString& rhs)
{
	if (lhs.size() != rhs.size())
		return false;
	for (size_t i = 0; i < lhs.size(); i++)
	{
		if (lhs[i] != rhs[i])
			return false;
	}
	return true;
}
开发者ID:qqingvarqq,项目名称:universitu_second_course_programming_source_code,代码行数:11,代码来源:MyString.cpp

示例5: isLegalName

bool isLegalName(MyString name)
{
    for (int i = 0; i < name.size(); ++i)
    {
        if (!isLegalChar(name[i]))
            return false;
    }
    if (name.startWith(_T(" ")) || name.size() > g_MAX_NAME_SIZE)
        return false;
    return true;
}
开发者ID:unoyx,项目名称:vfs,代码行数:11,代码来源:path.cpp

示例6: getSwitch

static int getSwitch(const MyString& cmd, int pos, MyString* s)
{
    int i = pos;
    while (i < cmd.size() && !_istgraph(cmd[i]))
        ++i;
    // 仅有首个字符为"\"
    int j = i + 1;
    while (j < cmd.size() && _istalpha(cmd[j]))
        ++j;
    *s = cmd.substr(i, j - i);
    return j;
}
开发者ID:unoyx,项目名称:vfs,代码行数:12,代码来源:CommandParser.cpp

示例7: getCmd

// 取得命令名
static int getCmd(const MyString& cmd, int pos, MyString* name)
{
    int i = pos;
    while (i < cmd.size() && !_istgraph(cmd[i]))
        ++i;

    int j = i;
    while (j < cmd.size() && _istalpha(cmd[j]))
        ++j;
    // 仅在识别出类似绝对路径时进行回溯
    if ((i + 1) < cmd.size() && _istalpha(cmd[i]) && cmd[i + 1] == _T(':'))
        return i;

    *name = cmd.substr(i, j - i);
    return j;
}
开发者ID:unoyx,项目名称:vfs,代码行数:17,代码来源:CommandParser.cpp

示例8: dirname

MyString dirname(MyString path)
{
    assert(isPath(path));
    int pos = path.size() - 1;
    for (; pos >= 0 && path[pos] != _T('\\'); --pos)
    {
    }
    return path.substr(0, pos);
}
开发者ID:unoyx,项目名称:vfs,代码行数:9,代码来源:path.cpp

示例9: join

MyString join(MyString path, MyString name)
{
    if (path[path.size() - 1] != _T('\\') && !name.isEmpty() && !name.startWith(_T("\\")))
    {
        path += _T("\\");
    }
    path += name;
    return path;
}
开发者ID:unoyx,项目名称:vfs,代码行数:9,代码来源:path.cpp

示例10: basename

MyString basename(MyString path)
{
    assert(isPath(path));
    int pos = path.size() - 1;
    for (; pos >= 0 && path[pos] != _T('\\'); --pos)
    {
    }
    if (pos < 0)
    {
        return _T("");
    }
    return path.substr(pos + 1);
}
开发者ID:unoyx,项目名称:vfs,代码行数:13,代码来源:path.cpp

示例11: pathNormalize

// 不改变路径中的大小写情况
MyString VirtualDiskNode::pathNormalize(MyString path) const
{
    MyString ret;
    if (!isPath(path))
    {
        assert(0);
        return ret;
    }
    if (isVolumnRelative(path))
    {
        ret = join(m_pwd.substr(0, 2), path);
    }
    else if (isRelative(path))
    {
        if (path == _T("."))
        {
            ret = m_pwd;
        }
        else if (path == _T(".."))
        {
            ret = dirname(m_pwd);
        }
        else if (path.startWith(_T("..\\")))
        {
            ret = dirname(m_pwd) + path.substr(2);
        } 
        else if (path.startWith(_T(".\\")))
        {
            ret = m_pwd + path.substr(1);
        }
        // 直接输入名字的情况
        else if (!match(path, _T("?:*")))
        {
            ret = m_pwd + _T("\\") + path;
        }
    } 
    // 绝对路径中处理:\dir\file的情况
    //else if (path.startWith(_T("\\")))
    //{
    //    ret = _T("c:") + path;
    //}

    if (path.endWith(_T("\\")))
    {
        ret = ret.substr(0, ret.size() - 1);
    }
    return ret;
}
开发者ID:unoyx,项目名称:vfs,代码行数:49,代码来源:VirtualFileSystem.cpp

示例12: skipToEqual

// 在src中确定从位置pos开始,长度为len的范围内的首个与c匹配字符的位置
static int skipToEqual(const MyString& src, int pos, TCHAR c, int len = 0)
{
    assert(len >= 0);
    if (len == 0)
    {
        return src.find(c, pos);
    }
    for (int i = 0; i < len && (pos + i) < src.size(); ++i)
    {
        if (src[pos + i] == c)
        {
            return pos + i;
        }
    }
    return -1;
}
开发者ID:unoyx,项目名称:vfs,代码行数:17,代码来源:path.cpp

示例13: main

int main() {
	const MyString cs("Ein konstanter String"); MyString s(cs);
	s.assign(cs);
	s.append(cs);
	cout << cs.c_str() << endl;
	cout << cs.size() << endl;
	cout << cs.capacity() << endl;
	cout << boolalpha << cs.empty() << endl;
	s = cs + cs;
	cout << (cs == cs) << endl;
	s = cs;
	cout << cs << endl;
	s.at(1) = 'X';
	s[2] = 'Y'; // Hallo
	cout << s << endl;
	cin.get();
return 0;
}
开发者ID:HSE-SWB2-OOS,项目名称:OOS-LB3,代码行数:18,代码来源:main.cpp

示例14: main

int main()
   {
   cout << "Testing default constructor\n\n";

   const MyString s1;
   
   cout << "s1: " << s1 << endl;   			        	// Makes MyString
   cout << "s1 size: " << s1.size() << endl;			        // Gets stringSize
   cout << "s1 is " << ((s1.empty()) ? "empty\n" : "not empty\n");      // Displays weather string is empty or not
   cout << endl;							// Endl and goes onto next code chunk

   cout << "Testing second constructor\n\n";
   
   MyString s2 = "some text";
   
   cout << "s2: " << s2 << endl;
   cout << "s2 size: " << s2.size() << endl;
   cout << "s2 is " << ((s2.empty()) ? "empty\n" : "not empty\n");
   cout <<endl;
   
   cout << "Testing size limit on second constructor\n\n";
   
   MyString s3 = "This is a really long string and not all of it will actually end up in the array, but that is okay";
   
   cout << "s3: " << s3 << endl;   
   cout << "s3 size: " << s3.size() << endl;
   cout << "s3 is " << ((s3.empty()) ? "empty\n" : "not empty\n");
   cout << endl;

   cout << "Testing write form of subscript operator\n\n";
   
   s2[0] = 'S';
   s2[5] = 'T';
   cout << "s2: " << s2 << endl << endl;
      
   cout << "Testing read form of subscript operator\n\n";
   
   cout << "s2: ";
   for (unsigned int i = 0; i < s2.size(); i++)
      cout << s2[i];
   cout << endl << endl;

   cout << "Testing equality operators\n\n";

   const MyString s4 = "Some Text";
   
   cout << "s2 and s4 are " << ((s2 == s4) ? "equal\n" : "not equal\n");
   cout << "s3 and s4 are " << ((s3 == s4) ? "equal\n" : "not equal\n\n");
   
   cout << "s4 and \"Some Text\" are " << ((s4 == "Some Text") ? "equal\n" : "not equal\n");
   cout << "s4 and \"More Text\" are " << ((s4 == "More Text") ? "equal\n" : "not equal\n\n");
   
   cout << "\"Some Text\" and s4 are " << (("Some Text" == s4) ? "equal\n" : "not equal\n");
   cout << "\"More Text\" and s4 are " << (("More Text" == s4) ? "equal\n" : "not equal\n\n");

   cout << "Testing clear() method\n\n";

   s3.clear();
   
   cout << "s3: " << s3 << endl;   
   cout << "s3 size: " << s3.size() << endl;
   cout << "s3 is " << ((s3.empty()) ? "empty\n" : "not empty\n");

   return 0;
   }
开发者ID:BISmb,项目名称:CourseWork,代码行数:65,代码来源:driver.cpp

示例15: parse

int parse(const MyString& cmd, MyString* name, Vector<MyString>* pathes, Vector<MyString>* switches)
{
    if (name == nullptr || pathes == nullptr || switches == nullptr)
    {
        return -1;
    }

    pathes->clear();
    switches->clear();

    int i = getCmd(cmd, 0, name);
    if (i == cmd.size())
    {
        return 0;
    }
    if (*name == _T("mkdir"))
    {
        while (_istspace(cmd[i]))
            ++i;
        int j = cmd.size() - 1;
        while (_istspace(cmd[j]))
            --j;
        MyString path = cmd.substr(i, j - i + 1);
        pathes->append(path);
        return 0;
    }

    for (; i < cmd.size();)
    {
        if (_istspace(cmd[i]))
        {
            ++i;
        }
        else if (cmd[i] != _T('/'))
        {
            MyString path;
            i = getPath(cmd, i, &path);
            if (!isPath(path) && !hasWildcard(path))
            {
                printf("文件名、目录名或卷标语法不正确\n");
                *name = _T("");
                pathes->clear();
                switches->clear();
                return -1;
            }
            pathes->append(path);
        }
        else if (cmd[i] == _T('/'))
        {
            MyString s;
            i = getSwitch(cmd, i, &s);
            switches->append(s);
        }
        else
        {
            assert(0);
            return -1;
        }
    }
    return 0;
}
开发者ID:unoyx,项目名称:vfs,代码行数:61,代码来源:CommandParser.cpp


注:本文中的MyString::size方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。