Boost中string的大小写转换用法

头文件

boost/algorithm/string/case_conv.hpp

作用

主要有如下API

to_lower_copy:将原来字符串,转换为小写字符串,并返回新的字符串,原来字符串不改变。

to_upper_copy:将原来字符串,转换为大写字符串,并返回新的字符串,原来字符串不改变。

to_lower:将原来字符串,转换为小写字符串,原来字符串改变。

to_upper:将原来字符串,转换为大写字符串,原来字符串改变。

举例

#include <boost/algorithm/string/case_conv.hpp>

#include <string>
#include <iostream>
#include <algorithm>

using namespace std;
using namespace boost;

void conv_test()
{
    string str1("AbCdEfG 123 xxxYYYzZzZ");
    string str2("AbCdEfG 123 xxxYYYzZzZ");
    string str3("");
    const char pch[]="AbCdEfG 123 xxxYYYzZzZ";    
    unsigned int pchlen=sizeof(pch);

    char* pch1=new char[pchlen];
    std::copy(pch, pch+pchlen, pch1);
    char* pch2=new char[pchlen];
    std::copy(pch, pch+pchlen, pch2);

    // *** iterator tests *** //

    string strout;
    to_lower_copy( back_inserter(strout), str1 );
    BOOST_CHECK( strout=="abcdefg 123 xxxyyyzzzz" );
    strout.clear();
    to_upper_copy( back_inserter(strout), str1 );
    BOOST_CHECK( strout=="ABCDEFG 123 XXXYYYZZZZ" );

    strout.clear();
    to_lower_copy( back_inserter(strout), "AbCdEfG 123 xxxYYYzZzZ" );
    BOOST_CHECK( strout=="abcdefg 123 xxxyyyzzzz" );
    strout.clear();
    to_upper_copy( back_inserter(strout), "AbCdEfG 123 xxxYYYzZzZ" );
    BOOST_CHECK( strout=="ABCDEFG 123 XXXYYYZZZZ" );

    strout.clear();
    to_lower_copy( back_inserter(strout), pch1 );
    BOOST_CHECK( strout=="abcdefg 123 xxxyyyzzzz" );
    strout.clear();
    to_upper_copy( back_inserter(strout), pch1 );
    BOOST_CHECK( strout=="ABCDEFG 123 XXXYYYZZZZ" );

    // *** value passing tests *** //

    BOOST_CHECK( to_lower_copy( str1 )=="abcdefg 123 xxxyyyzzzz" );
    BOOST_CHECK( to_upper_copy( str1 )=="ABCDEFG 123 XXXYYYZZZZ" );

    BOOST_CHECK( to_lower_copy( str3 )=="" );
    BOOST_CHECK( to_upper_copy( str3 )=="" );

    // *** inplace tests *** //

    to_lower( str1 );
    BOOST_CHECK( str1=="abcdefg 123 xxxyyyzzzz" );
    to_upper( str2 );
    BOOST_CHECK( str2=="ABCDEFG 123 XXXYYYZZZZ" );

    // c-string modification
    to_lower( pch1 );
    BOOST_CHECK( string(pch1)=="abcdefg 123 xxxyyyzzzz" );
    to_upper( pch2 );
    BOOST_CHECK( string(pch2)=="ABCDEFG 123 XXXYYYZZZZ" );

    to_lower( str3 );
    BOOST_CHECK( str3=="" );
    to_upper( str3 );
    BOOST_CHECK( str3=="" );

    delete[] pch1;
    delete[] pch2;
}

// test main 
int main(int argc, char* [])
{
    conv_test();
    return 0;
}

源代码

namespace boost {
    namespace algorithm {

//  to_lower  -----------------------------------------------//

        //! Convert to lower case
        /*!
            Each element of the input sequence is converted to lower
            case. The result is a copy of the input converted to lower case.
            It is returned as a sequence or copied to the output iterator.

            \param Output An output iterator to which the result will be copied
            \param Input An input range
            \param Loc A locale used for conversion
            \return 
                An output iterator pointing just after the last inserted character or
                a copy of the input

            \note The second variant of this function provides the strong exception-safety guarantee
                
        */
        template<typename OutputIteratorT, typename RangeT>
        inline OutputIteratorT 
        to_lower_copy(
            OutputIteratorT Output,
            const RangeT& Input,
            const std::locale& Loc=std::locale())
        {
            return ::boost::algorithm::detail::transform_range_copy( 
               Output,
               ::boost::as_literal(Input),
               ::boost::algorithm::detail::to_lowerF<
                    typename range_value<RangeT>::type >(Loc));
        }

        //! Convert to lower case
        /*!
            \overload
        */
        template<typename SequenceT>
        inline SequenceT to_lower_copy( 
            const SequenceT& Input, 
            const std::locale& Loc=std::locale())
        {
            return ::boost::algorithm::detail::transform_range_copy<SequenceT>(
                Input,
                ::boost::algorithm::detail::to_lowerF<
                    typename range_value<SequenceT>::type >(Loc));
        }

        //! Convert to lower case
        /*!
            Each element of the input sequence is converted to lower
            case. The input sequence is modified in-place.

            \param Input A range
            \param Loc a locale used for conversion
        */
        template<typename WritableRangeT>
        inline void to_lower( 
            WritableRangeT& Input, 
            const std::locale& Loc=std::locale())
        {
            ::boost::algorithm::detail::transform_range(
                ::boost::as_literal(Input),
                ::boost::algorithm::detail::to_lowerF<
                    typename range_value<WritableRangeT>::type >(Loc));
        }
        
//  to_upper  -----------------------------------------------//

        //! Convert to upper case
        /*!
            Each element of the input sequence is converted to upper
            case. The result is a copy of the input converted to upper case.
            It is returned as a sequence or copied to the output iterator

            \param Output An output iterator to which the result will be copied
            \param Input An input range
            \param Loc A locale used for conversion
            \return 
                An output iterator pointing just after the last inserted character or
                a copy of the input

            \note The second variant of this function provides the strong exception-safety guarantee
        */
        template<typename OutputIteratorT, typename RangeT>
        inline OutputIteratorT 
        to_upper_copy(
            OutputIteratorT Output,
            const RangeT& Input,
            const std::locale& Loc=std::locale())
        {
            return ::boost::algorithm::detail::transform_range_copy( 
               Output,
               ::boost::as_literal(Input),
               ::boost::algorithm::detail::to_upperF<
                    typename range_value<RangeT>::type >(Loc));
        }

        //! Convert to upper case
        /*!
            \overload
        */
        template<typename SequenceT>
        inline SequenceT to_upper_copy( 
            const SequenceT& Input, 
            const std::locale& Loc=std::locale())
        {
            return ::boost::algorithm::detail::transform_range_copy<SequenceT>(
                Input,
                ::boost::algorithm::detail::to_upperF<
                    typename range_value<SequenceT>::type >(Loc));
        }

        //! Convert to upper case
        /*!
            Each element of the input sequence is converted to upper
            case. The input sequence is modified in-place.

            \param Input An input range
            \param Loc a locale used for conversion
        */
        template<typename WritableRangeT>
        inline void to_upper( 
            WritableRangeT& Input, 
            const std::locale& Loc=std::locale())
        {
            ::boost::algorithm::detail::transform_range(
                ::boost::as_literal(Input),
                ::boost::algorithm::detail::to_upperF<
                    typename range_value<WritableRangeT>::type >(Loc));
        }

    } // namespace algorithm

    // pull names to the boost namespace
    using algorithm::to_lower;
    using algorithm::to_lower_copy;
    using algorithm::to_upper;
    using algorithm::to_upper_copy;

} // namespace boost

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Boost升压电路,IGBT(Insulated Gate Bipolar Transistor)是一种常用的功率开关器件,主要用于控制电流的流动。IGBT流过的电流大小取决于以下几个因素: 1. 输入电压:Boost升压电路的输入电压是决定IGBT流过电流的重要参数之一。输入电压的大小将决定升压倍数和负载电流的需求。 2. 负载电流:负载电流是IGBT所承受的主要电流,也是计算其流过电流大小的关键参数。负载电流可以通过负载电阻或负载器件的额定电流来确定。 3. 占空比:占空比是指在一个周期内,IGBT导通时间与总周期时间之比。占空比的大小将影响IGBT的平均导通电流。通常,占空比越大,平均导通电流也越大。 4. IGBT特性和参数:IGBT的额定电流、最大耗散功率以及热特性等参数也需要考虑。这些参数可以从IGBT的规格书或数据手册获取。 一般来说,可以通过以下方式估算IGBT流过的电流大小: IGBT流过电流 = 输入电压 × 负载电流 / (占空比 × 系统效率) 其,系统效率考虑了电路的损耗和效率,一般取值在0.8到0.9之间。 需要注意的是,这个计算方式是一个近似估算,实际的电流大小可能会受到电路设计、IGBT的特性和保护机制等因素的影响。为了确保电路的可靠性和安全性,建议参考相关的电路设计手册、IGBT的规格书或咨询专业的电源工程师来获取准确的IGBT流过电流值。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值