當前位置: 首頁>>代碼示例>>C#>>正文


C# Thread.GetTable方法代碼示例

本文整理匯總了C#中System.Thread.GetTable方法的典型用法代碼示例。如果您正苦於以下問題:C# Thread.GetTable方法的具體用法?C# Thread.GetTable怎麽用?C# Thread.GetTable使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Thread的用法示例。


在下文中一共展示了Thread.GetTable方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: SGsub

        private static int SGsub( Thread l )
        {
            var str = (LString)l[1];
            var pat = (LString)l[2];

            var subst = l[3];
            var subTy = subst.ValueType;

            switch( subTy )
            {
            case LValueType.Number:
                l.ConvertToString( ref subst );
                break;

            case LValueType.String:
            case LValueType.Function:
            case LValueType.Table:
                break;

            default:
                throw new ArgumentException( "string/function/table expected" );
            }

            var max = l.StackTop >= 4 ? (int)l[4] : int.MaxValue;

            MatchState ms;
            InitMatchState( out ms, l );

            ms.Str = str.InternalData;
            ms.StrInit = LString.BufferDataOffset;

            ms.Pat = pat.InternalData;
            int patInit = LString.BufferDataOffset;

            bool anchor = patInit < ms.Pat.Length && ms.Pat[patInit] == (byte)'^';
            if( anchor )
                patInit++;

            var strBuilder = l.GetStrBuilder( str.Length * 2 );

            int sPos = LString.BufferDataOffset;

            int n = 0;
            while( n < max )
            {
                ms.Level = 0;
                Debug.Assert( ms.MatchDepth == MaxCCalls );

                var e = SMatch( ref ms, sPos, patInit );
                if( e != -1 )
                {
                    n++;

                    Value substVal;

                    switch( subTy )
                    {
                    case LValueType.Function:
                        {
                            l.Push( subst );

                            var nCap = PushCaptures( ref ms, sPos, e, false );
                            l.Call( nCap, 1 );

                            substVal = l.PopValue();
                        }
                        break;

                    case LValueType.Table:
                        PushCapture( ref ms, 0, sPos, e );
                        substVal = l.GetTable( (Table)subst, l.PopValue() );
                        break;

                    case LValueType.Number:
                        //it's already been made a string
                        substVal = subst;
                        break;

                    case LValueType.String:
                        //need to handle escape sequences
                        {
                            var sb = (byte[])subst.RefVal;
                            for( int i = LString.BufferDataOffset; i < sb.Length; i++ )
                            {
                                var ch = sb[i];

                                if( ch != (byte)'%' )
                                {
                                    strBuilder.Append( ch );
                                    continue;
                                }

                                if( ++i == sb.Length )
                                    throw new ArgumentException( "Invalid use of % in replacement string" );

                                ch = sb[i];

                                if( ch == (byte)'%' )
                                {
                                    strBuilder.Append( ch );
//.........這裏部分代碼省略.........
開發者ID:henchmeninteractive,項目名稱:HenchLua,代碼行數:101,代碼來源:StringLib.cs


注:本文中的System.Thread.GetTable方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。