字符串间隔如何工作?

字符串间隔如何工作?,第1张

概述我在 this answer做了一些游戏,甚至向Apple提出了RADAR问题,要求提供更好的文件记录(蟋蟀唧唧喳喳). 问题是:字符串间隔如何工作? 如果你看看我 *** 场上的第367行,你会发现我在乱用字符串间隔. 我将String的东西提取到一个较小的游乐场: // String Intervals// These are odd. Looks like it is using the ASCI 我在 this answer做了一些游戏,甚至向Apple提出了RADAR问题,要求提供更好的文件记录(蟋蟀唧唧喳喳).

问题是:字符串间隔如何工作?

如果你看看我 *** 场上的第367行,你会发现我在乱用字符串间隔.

我将String的东西提取到一个较小的游乐场:

// String Intervals// These are odd. Looks like it is using the ASCII values. I should experiment with Unicode,and see where we go...let aThroughFClosed:ClosedInterval<String>          = "A"..."F"let dThroughQClosed:ClosedInterval                  = "D"..."Q"let mThroughSClosed:ClosedInterval                  = "M"..."S"let tThroughWClosed:ClosedInterval                  = "T"..."W"let whiskeyTangoFoxtrot1                            = "QED"..."WTF" /* Not sure what will happen when I start working with this... */let aThroughHHalfOpen:HalfOpenInterval<String>      = "A"..<"H"let dThroughRHalfOpen:HalfOpenInterval              = "D"..<"R"let mThroughTHalfOpen:HalfOpenInterval              = "M"..<"T"let tThroughXHalfOpen:HalfOpenInterval              = "T"..<"X"let whiskeyTangoFoxtrot2                            = "QED"..<"WTF"let clampedString1 = aThroughFClosed.clamp ( dThroughQClosed )  /* This represents "D"..."F" */let clampedString2 = dThroughQClosed.clamp ( aThroughFClosed )  /* This represents "D"..."F" */let clampedString3 = dThroughQClosed.clamp ( mThroughSClosed )  /* This represents "M"..."Q" */let clampedString4 = dThroughQClosed.clamp ( tThroughWClosed )  /* This represents "Q"..."Q" */let clampedString5 = aThroughFClosed.clamp ( tThroughWClosed )  /* This represents "F"..."F" */let clampedString6 = aThroughHHalfOpen.clamp ( dThroughRHalfOpen )  /* This represents "D"..<"G" */let clampedString7 = dThroughRHalfOpen.clamp ( aThroughHHalfOpen )  /* This represents "D"..<"H" */let clampedString8 = dThroughRHalfOpen.clamp ( mThroughTHalfOpen )  /* This represents "M"..<"R" */let clampedString9 = dThroughRHalfOpen.clamp ( tThroughXHalfOpen )  /* This represents "R"..<"R" */let clampedString0 = aThroughHHalfOpen.clamp ( tThroughXHalfOpen )  /* This represents "H"..<"H" (Not exactly sure why) */// 2.2.3: STRING INTERVALS// String intervals are weird. Just sayin'...// 2.2.3.1: STRING INTERVALS AS SWITCH TESTSvar testValue3:String = "B"switch ( testValue3 )    {case aThroughFClosed:   /* This will catch it. */    println ( "In A...F." )default:    println ( "In catchall." )}// Looks like the test is only on the first letter.testValue3 = "Badz-Maru"switch ( testValue3 )    {case aThroughFClosed:   /* This will catch it. */    println ( "In A...F." )default:    println ( "In catchall." )}testValue3 = "\tBadz-Maru"   /* If we add a tab character to the start of the string,then the first test will fail. */switch ( testValue3 )    {case aThroughFClosed:    println ( "In A...F." )default:    /* This will catch it. */    println ( "In catchall." )}// Now,we'll get really strange. Let's look at our multi-character intervals...testValue3 = "W"switch ( testValue3 )    {case whiskeyTangoFoxtrot2:  /* This catches it. */    println ( "WTF,dude?" )default:    println ( "In catchall." )}testValue3 = "T"switch ( testValue3 )    {case whiskeyTangoFoxtrot2:  /* This catches it. */    println ( "WTF,dude?" )default:    println ( "In catchall." )}testValue3 = "F"switch ( testValue3 )    {case whiskeyTangoFoxtrot2:    println ( "WTF,dude?" )default: /* However,in this case,it falls through to default. */    println ( "In catchall." )}testValue3 = "WT"switch ( testValue3 )    {case whiskeyTangoFoxtrot2: /* "WT" is caught. */    println ( "WTF,dude?" )default:    println ( "In catchall." )}testValue3 = "WTF"switch ( testValue3 )    {case whiskeyTangoFoxtrot2:    println ( "WTF,dude?" )default:    /* "WTF" is not caught. */    println ( "In catchall." )}testValue3 = "QED"switch ( testValue3 )    {case whiskeyTangoFoxtrot2:  /* "QED" is caught. */    println ( "WTF,dude?" )default:    println ( "In catchall." )}testValue3 = "QTF"switch ( testValue3 )    {case whiskeyTangoFoxtrot2:  /* "QTF" is caught. */    println ( "WTF,dude?" )default:    println ( "In catchall." )}testValue3 = "QSF"switch ( testValue3 )    {case whiskeyTangoFoxtrot2:  /* "QSF" is caught. */    println ( "WTF,dude?" )default:    println ( "In catchall." )}testValue3 = "QAF"switch ( testValue3 )    {case whiskeyTangoFoxtrot2:    println ( "WTF,dude?" )default: /* QAF falls through. */    println ( "In catchall." )}
解决方法 据我了解,ClosedInterval(lo,hi)表示所有字符串

lo <= s <= hi

和HalfOpenInterval(lo,hi)表示所有字符串

lo <= s < hi

其中< =和<由字符串的字典排序决定,
即逐个比较字符,直到找到差异.

例如“QED”< “T”< “WTF”因为Q< T< W,但是“F”< “QED”因为
F<问:因此

HalfOpenInterval("QED","WTF").contains("T") == trueHalfOpenInterval("QED","WTF").contains("F") == false

并且“QED”< “QSF”,因为Q == Q和E< S,但“QAF”< “QED”因为Q == Q且A< E.因此

HalfOpenInterval("QED","WTF").contains("QSF") == trueHalfOpenInterval("QED","WTF").contains("QAF") == false

这应该解释你所有的测试结果.

最后,

let clampedString0 = aThroughHHalfOpen.clamp ( tThroughXHalfOpen )

因为“A”……<“H”和“T”......<“X”没有共同点.对于任何空间,可以用HalfOpenInterval(dummy,dummy)表示空间隔虚拟的价值.

总结

以上是内存溢出为你收集整理的字符串间隔如何工作?全部内容,希望文章能够帮你解决字符串间隔如何工作?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1007179.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存