1913 withoutSpaces |
1926 withoutSpaces |
1914 "return a copy of myself without leading and trailing spaces" |
1927 "return a copy of myself without leading and trailing spaces" |
1915 |
1928 |
1916 |startIndex "{ Class: SmallInteger }" |
1929 |startIndex "{ Class: SmallInteger }" |
1917 endIndex "{ Class: SmallInteger }" |
1930 endIndex "{ Class: SmallInteger }" |
1918 blank| |
1931 sz blank| |
1919 |
1932 |
1920 startIndex := 1. |
1933 %{ |
1921 endIndex := self size. |
1934 REGISTER unsigned char *cp0; |
1922 blank := Character space. |
1935 REGISTER unsigned char *cp; |
1923 [(startIndex < endIndex) and:[(self at:startIndex) == blank]] whileTrue:[ |
1936 |
1924 startIndex := startIndex + 1 |
1937 /* ignore instances of subclasses ... */ |
1925 ]. |
1938 if (_qClass(self) == String) { |
1926 [(endIndex > 1) and:[(self at:endIndex) == blank]] whileTrue:[ |
1939 cp = cp0 = _stringVal(self); |
1927 endIndex := endIndex - 1 |
1940 while (*cp == ' ') cp++; |
|
1941 startIndex = _MKSMALLINT(cp - cp0 + 1); |
|
1942 cp = cp + strlen(cp) - 1; |
|
1943 while ((cp >= cp0) && (*cp == ' ')) cp--; |
|
1944 endIndex = _MKSMALLINT(cp - cp0 + 1); |
|
1945 } |
|
1946 %} |
|
1947 . |
|
1948 sz := self size. |
|
1949 startIndex isNil ifTrue:[ |
|
1950 startIndex := 1. |
|
1951 endIndex := sz. |
|
1952 blank := Character space. |
|
1953 [(startIndex < endIndex) and:[(self at:startIndex) == blank]] whileTrue:[ |
|
1954 startIndex := startIndex + 1 |
|
1955 ]. |
|
1956 [(endIndex > 1) and:[(self at:endIndex) == blank]] whileTrue:[ |
|
1957 endIndex := endIndex - 1 |
|
1958 ] |
1928 ]. |
1959 ]. |
1929 startIndex > endIndex ifTrue:[ |
1960 startIndex > endIndex ifTrue:[ |
1930 ^ '' |
1961 ^ '' |
1931 ]. |
1962 ]. |
1932 ((startIndex == 1) and:[endIndex == self size]) ifTrue:[ |
1963 ((startIndex == 1) and:[endIndex == sz]) ifTrue:[ |
1933 ^ self |
1964 ^ self |
1934 ]. |
1965 ]. |
1935 ^ self copyFrom:startIndex to:endIndex |
1966 ^ self copyFrom:startIndex to:endIndex |
1936 ! |
1967 ! |
1937 |
1968 |
1938 withoutSeparators |
1969 withoutSeparators |
1939 "return a copy of myself without leading and trailing whitespace" |
1970 "return a copy of myself without leading and trailing whitespace" |
1940 |
1971 |
1941 |startIndex "{ Class: SmallInteger }" |
1972 |startIndex "{ Class: SmallInteger }" |
1942 endIndex "{ Class: SmallInteger }" | |
1973 endIndex "{ Class: SmallInteger }" |
1943 |
1974 sz| |
1944 startIndex := 1. |
1975 |
1945 endIndex := self size. |
1976 %{ |
1946 [(startIndex < endIndex) and:[(self at:startIndex) isSeparator]] whileTrue:[ |
1977 REGISTER unsigned char *cp0; |
1947 startIndex := startIndex + 1 |
1978 REGISTER unsigned char *cp; |
1948 ]. |
1979 REGISTER unsigned char c; |
1949 [(endIndex > 1) and:[(self at:endIndex) isSeparator]] whileTrue:[ |
1980 |
1950 endIndex := endIndex - 1 |
1981 /* ignore instances of subclasses ... */ |
|
1982 if (_qClass(self) == String) { |
|
1983 cp = cp0 = _stringVal(self); |
|
1984 c = *cp; |
|
1985 while ((c == ' ') || (c == '\n') || (c == '\t') |
|
1986 || (c == '\r') || (c == '\f')) { |
|
1987 cp++; |
|
1988 c = *cp; |
|
1989 } |
|
1990 startIndex = _MKSMALLINT(cp - cp0 + 1); |
|
1991 cp = cp + strlen(cp) - 1; |
|
1992 while ((cp >= cp0) && (*cp == ' ')) cp--; |
|
1993 c = *cp; |
|
1994 while ((cp >= cp0) && |
|
1995 ((c == ' ') || (c == '\n') || (c == '\t') |
|
1996 || (c == '\r') || (c == '\f'))) { |
|
1997 cp--; |
|
1998 c = *cp; |
|
1999 } |
|
2000 endIndex = _MKSMALLINT(cp - cp0 + 1); |
|
2001 } |
|
2002 %} |
|
2003 . |
|
2004 sz := self size. |
|
2005 startIndex isNil ifTrue:[ |
|
2006 startIndex := 1. |
|
2007 endIndex := self size. |
|
2008 [(startIndex < endIndex) and:[(self at:startIndex) isSeparator]] whileTrue:[ |
|
2009 startIndex := startIndex + 1 |
|
2010 ]. |
|
2011 [(endIndex > 1) and:[(self at:endIndex) isSeparator]] whileTrue:[ |
|
2012 endIndex := endIndex - 1 |
|
2013 ]. |
1951 ]. |
2014 ]. |
1952 startIndex > endIndex ifTrue:[ |
2015 startIndex > endIndex ifTrue:[ |
1953 ^ '' |
2016 ^ '' |
1954 ]. |
2017 ]. |
1955 ((startIndex == 1) and:[endIndex == self size]) ifTrue:[ |
2018 ((startIndex == 1) and:[endIndex == sz]) ifTrue:[ |
1956 ^ self |
2019 ^ self |
1957 ]. |
2020 ]. |
1958 ^ self copyFrom:startIndex to:endIndex |
2021 ^ self copyFrom:startIndex to:endIndex |
1959 ! ! |
2022 ! ! |
1960 |
2023 |