你好這個問題我已經研究過了,有人說這是Java的RegEx錯誤,但我甚至都不認爲Energia使用Java。有點困惑,爲什麼這個錯誤是與C代碼彈出。Base 64編碼很長的字符串Java Overflow,Arduino Energia IDE,TI CC3200
錯誤:
Exception in thread "Thread-5" java.lang.StackOverflowError
at java.util.regex.Pattern$Loop.match(Pattern.java:4295)
at java.util.regex.Pattern$GroupTail.match(Pattern.java:4227)
at java.util.regex.Pattern$BranchConn.match(Pattern.java:4078)
at java.util.regex.Pattern$CharProperty.match(Pattern.java:3345)
at java.util.regex.Pattern$Branch.match(Pattern.java:4114)
at java.util.regex.Pattern$GroupHead.match(Pattern.java:4168)
at java.util.regex.Pattern$Loop.match(Pattern.java:4295)
at java.util.regex.Pattern$GroupTail.match(Pattern.java:4227)
at java.util.regex.Pattern$BranchConn.match(Pattern.java:4078)
at java.util.regex.Pattern$CharProperty.match(Pattern.java:3345)
at java.util.regex.Pattern$Branch.match(Pattern.java:4114)
...它的推移數百同樣的東西更多的線路。
至於正則表達式代碼:
注意,在這種情況下,我在部分硬編碼爲我的形象(這是造成錯誤的字段),只是爲了測試目的,我要傳遞的JSON消息通過網絡將base64編碼轉換爲Web服務,然後將其作爲圖片傳遞給我的電子郵件。
如果圖像字符串被縮短,則不會發生錯誤,但當然這是傳輸實際圖片的字符串太小。非常感謝您的幫助!
// [7.12.2] Class template regex_token_iterator
/**
* Iterates over submatches in a range (or @a splits a text string).
*
* The purpose of this iterator is to enumerate all, or all specified,
* matches of a regular expression within a text range. The dereferenced
* value of an iterator of this class is a std::tr1::sub_match object.
*/
template<typename _Bi_iter,
typename _Ch_type = typename iterator_traits<_Bi_iter>::value_type,
typename _Rx_traits = regex_traits<_Ch_type> >
class regex_token_iterator
{
public:
typedef basic_regex<_Ch_type, _Rx_traits> regex_type;
typedef sub_match<_Bi_iter> value_type;
typedef std::ptrdiff_t difference_type;
typedef const value_type* pointer;
typedef const value_type& reference;
typedef std::forward_iterator_tag iterator_category;
public:
/**
* @brief Default constructs a %regex_token_iterator.
* @todo Implement this function.
*
* A default-constructed %regex_token_iterator is a singular iterator
* that will compare equal to the one-past-the-end value for any
* iterator of the same type.
*/
regex_token_iterator();
/**
* Constructs a %regex_token_iterator...
* @param a [IN] The start of the text to search.
* @param b [IN] One-past-the-end of the text to search.
* @param re [IN] The regular expression to search for.
* @param submatch [IN] Which submatch to return. There are some
* special values for this parameter:
* - -1 each enumerated subexpression does NOT
* match the regular expression (aka field
* splitting)
* - 0 the entire string matching the
* subexpression is returned for each match
* within the text.
* - >0 enumerates only the indicated
* subexpression from a match within the text.
* @param m [IN] Policy flags for match rules.
*
* @todo Implement this function.
* @doctodo
*/
regex_token_iterator(_Bi_iter __a, _Bi_iter __b, const regex_type& __re,
int __submatch = 0,
regex_constants::match_flag_type __m
= regex_constants::match_default);
/**
* Constructs a %regex_token_iterator...
* @param a [IN] The start of the text to search.
* @param b [IN] One-past-the-end of the text to search.
* @param re [IN] The regular expression to search for.
* @param submatches [IN] A list of subexpressions to return for each
* regular expression match within the text.
* @param m [IN] Policy flags for match rules.
*
* @todo Implement this function.
* @doctodo
*/
regex_token_iterator(_Bi_iter __a, _Bi_iter __b,
const regex_type& __re,
const std::vector<int>& __submatches,
regex_constants::match_flag_type __m
= regex_constants::match_default);
/**
* Constructs a %regex_token_iterator...
* @param a [IN] The start of the text to search.
* @param b [IN] One-past-the-end of the text to search.
* @param re [IN] The regular expression to search for.
* @param submatches [IN] A list of subexpressions to return for each
* regular expression match within the text.
* @param m [IN] Policy flags for match rules.
* @todo Implement this function.
* @doctodo
*/
template<std::size_t _Nm>
regex_token_iterator(_Bi_iter __a, _Bi_iter __b,
const regex_type& __re,
const int (&__submatches)[_Nm],
regex_constants::match_flag_type __m
= regex_constants::match_default);
/**
* @brief Copy constructs a %regex_token_iterator.
* @param rhs [IN] A %regex_token_iterator to copy.
* @todo Implement this function.
*/
regex_token_iterator(const regex_token_iterator& __rhs);
/**
* @brief Assigns a %regex_token_iterator to another.
* @param rhs [IN] A %regex_token_iterator to copy.
* @todo Implement this function.
*/
regex_token_iterator&
operator=(const regex_token_iterator& __rhs);
/**
* @brief Compares a %regex_token_iterator to another for equality.
* @todo Implement this function.
*/
bool
operator==(const regex_token_iterator& __rhs);
/**
* @brief Compares a %regex_token_iterator to another for inequality.
* @todo Implement this function.
*/
bool
operator!=(const regex_token_iterator& __rhs);
/**
* @brief Dereferences a %regex_token_iterator.
* @todo Implement this function.
*/
const value_type&
operator*();
/**
* @brief Selects a %regex_token_iterator member.
* @todo Implement this function.
*/
const value_type*
operator->();
/**
* @brief Increments a %regex_token_iterator.
* @todo Implement this function.
*/
regex_token_iterator&
operator++();
/**
* @brief Postincrements a %regex_token_iterator.
* @todo Implement this function.
*/
regex_token_iterator
operator++(int);
private: // data members for exposition only:
typedef regex_iterator<_Bi_iter, _Ch_type, _Rx_traits> position_iterator;
position_iterator __position;
const value_type* __result;
value_type __suffix;
std::size_t __n;
std::vector<int> __subs;
};
/** @brief Token iterator for C-style NULL-terminated strings. */
typedef regex_token_iterator<const char*> cregex_token_iterator;
/** @brief Token iterator for standard strings. */
typedef regex_token_iterator<string::const_iterator> sregex_token_iterator;
#ifdef _GLIBCXX_USE_WCHAR_T
/** @brief Token iterator for C-style NULL-terminated wide strings. */
typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator;
/** @brief Token iterator for standard wide-character strings. */
typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;
#endif
base64.c:
#include <string.h>
#include "base64.h"
/* aaaack but it's fast and const should make it shared text page. */
static const unsigned char pr2six[256] =
{
/* ASCII table */
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 62, 64, 64, 64, 63,
52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 64, 64, 64, 64, 64, 64,
64, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 64, 64, 64, 64, 64,
64, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64
};
int Base64decode_len(const char *bufcoded)
{
int nbytesdecoded;
register const unsigned char *bufin;
register int nprbytes;
bufin = (const unsigned char *) bufcoded;
while (pr2six[*(bufin++)] <= 63);
nprbytes = (bufin - (const unsigned char *) bufcoded) - 1;
nbytesdecoded = ((nprbytes + 3)/4) * 3;
return nbytesdecoded + 1;
}
int Base64decode(char *bufplain, const char *bufcoded)
{
int nbytesdecoded;
register const unsigned char *bufin;
register unsigned char *bufout;
register int nprbytes;
bufin = (const unsigned char *) bufcoded;
while (pr2six[*(bufin++)] <= 63);
nprbytes = (bufin - (const unsigned char *) bufcoded) - 1;
nbytesdecoded = ((nprbytes + 3)/4) * 3;
bufout = (unsigned char *) bufplain;
bufin = (const unsigned char *) bufcoded;
while (nprbytes > 4) {
*(bufout++) =
(unsigned char) (pr2six[*bufin] << 2 | pr2six[bufin[1]] >> 4);
*(bufout++) =
(unsigned char) (pr2six[bufin[1]] << 4 | pr2six[bufin[2]] >> 2);
*(bufout++) =
(unsigned char) (pr2six[bufin[2]] << 6 | pr2six[bufin[3]]);
bufin += 4;
nprbytes -= 4;
}
/* Note: (nprbytes == 1) would be an error, so just ingore that case */
if (nprbytes > 1) {
*(bufout++) =
(unsigned char) (pr2six[*bufin] << 2 | pr2six[bufin[1]] >> 4);
}
if (nprbytes > 2) {
*(bufout++) =
(unsigned char) (pr2six[bufin[1]] << 4 | pr2six[bufin[2]] >> 2);
}
if (nprbytes > 3) {
*(bufout++) =
(unsigned char) (pr2six[bufin[2]] << 6 | pr2six[bufin[3]]);
}
*(bufout++) = '\0';
nbytesdecoded -= (4 - nprbytes) & 3;
return nbytesdecoded;
}
static const char basis_64[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz/";
int Base64encode_len(int len)
{
return ((len + 2)/3 * 4) + 1;
}
int Base64encode(char *encoded, const char *string, int len)
{
int i;
char *p;
p = encoded;
for (i = 0; i < len - 2; i += 3) {
*p++ = basis_64[(string[i] >> 2) & 0x3F];
*p++ = basis_64[((string[i] & 0x3) << 4) |
((int) (string[i + 1] & 0xF0) >> 4)];
*p++ = basis_64[((string[i + 1] & 0xF) << 2) |
((int) (string[i + 2] & 0xC0) >> 6)];
*p++ = basis_64[string[i + 2] & 0x3F];
}
if (i < len) {
*p++ = basis_64[(string[i] >> 2) & 0x3F];
if (i == (len - 1)) {
*p++ = basis_64[((string[i] & 0x3) << 4)];
*p++ = '=';
}
else {
*p++ = basis_64[((string[i] & 0x3) << 4) |
((int) (string[i + 1] & 0xF0) >> 4)];
*p++ = basis_64[((string[i + 1] & 0xF) << 2)];
}
*p++ = '=';
}
*p++ = '\0';
return p - encoded;
}
base64.h:
#ifndef _BASE64_H_
#define _BASE64_H_
#ifdef __cplusplus
extern "C" {
#endif
int Base64encode_len(int len);
int Base64encode(char * coded_dst, const char *plain_src,int len_plain_src);
int Base64decode_len(const char * coded_src);
int Base64decode(char * plain_dst, const char *coded_src);
#ifdef __cplusplus
}
#endif
#endif //_BASE64_H_
爲了進一步解釋:這個錯誤被觸發,當我嘗試插入帶有預編碼的base64 JPEG圖像文本...我想確保在嘗試實例化嵌入式相機之前,我可以傳輸虛擬圖像。我很確定這不是base64代碼,而是我對此一無所知的Java正則表達式(簡單來說,它處理標記長字符串並似乎與錯誤有關)。也許它試圖在字符串中找到一個模式,因爲它是一個很長的隨機字符串,它不能做到這一點,然後錯誤?
這個錯誤確實暗示了一個正則表達式需要太多「步驟」才能找到匹配的問題。請分享這個正則表達式。 –
當您嘗試編輯該文件時,Energia IDE會拋出此錯誤嗎? –
你分享的代碼是一種無趣的代碼 - 需要幫助你的代碼在'Base64encode'方法中。你可以分享'base64.h' /'base64.c'嗎? – ClasG