/** * @bug 4104136 */ void DateFormatRegressionTest::Test4104136(void) { UErrorCode status = U_ZERO_ERROR; SimpleDateFormat *sdf = new SimpleDateFormat(status); if(U_FAILURE(status)) { dataerrln("Couldn't create SimpleDateFormat, error %s", u_errorName(status)); delete sdf; return; } if(failure(status, "new SimpleDateFormat")) return; UnicodeString pattern = "'time' hh:mm"; sdf->applyPattern(pattern); logln("pattern: \"" + pattern + "\""); UnicodeString strings [] = { (UnicodeString)"time 10:30", (UnicodeString) "time 10:x", (UnicodeString) "time 10x" }; ParsePosition ppos [] = { ParsePosition(10), ParsePosition(0), ParsePosition(0) }; UDate dates [] = { date(70, UCAL_JANUARY, 1, 10, 30), -1, -1 }; /*Object[] DATA = { "time 10:30", new ParsePosition(10), new Date(70, Calendar.JANUARY, 1, 10, 30), "time 10:x", new ParsePosition(0), null, "time 10x", new ParsePosition(0), null, };*/ for(int i = 0; i < 3; i++) { UnicodeString text = strings[i]; ParsePosition finish = ppos[i]; UDate exp = dates[i]; ParsePosition pos(0); UDate d = sdf->parse(text, pos); logln(" text: \"" + text + "\""); logln(" index: %d", pos.getIndex()); logln((UnicodeString) " result: " + d); if(pos.getIndex() != finish.getIndex()) errln("Fail: Expected pos " + finish.getIndex()); if (! ((d == 0 && exp == -1) || (d == exp))) errln((UnicodeString) "Fail: Expected result " + exp); } delete sdf; }
// 设置位置信息(指定父对象位置) BOOL CControlBase::SetPositionWithParent(CRect rectParent) { if(m_strPos.IsEmpty()) { return FALSE; } DUI_POSITION pos; pos.nCount = 0; LPCTSTR pszValue = m_strPos; while(pos.nCount < 4 && pszValue) { pszValue=ParsePosition(pszValue, pos.Item[pos.nCount++]); } if (2 == pos.nCount || 4 == pos.nCount) { if(4 == pos.nCount) { CRect rect; rect.left = PositionItem2Value(pos.Left, rectParent.left, rectParent.right); rect.top = PositionItem2Value(pos.Top, rectParent.top, rectParent.bottom); rect.right = PositionItem2Value(pos.Right, rectParent.left, rectParent.right); rect.bottom = PositionItem2Value(pos.Bottom, rectParent.top, rectParent.bottom); SetRect(rect); }else if(2 == pos.nCount) { CRect rect; rect.left = PositionItem2Value(pos.Left, rectParent.left, rectParent.right); rect.top = PositionItem2Value(pos.Top, rectParent.top, rectParent.bottom); if(m_nWidth != 0) { rect.right = rect.left + m_nWidth; }else { rect.right = PositionItem2Value(pos.Left, rectParent.left, rectParent.right); } if(m_nHeight != 0) { rect.bottom = rect.top + m_nHeight; }else { rect.bottom = PositionItem2Value(pos.Top, rectParent.top, rectParent.bottom); } SetRect(rect); } }else { pos.nCount = 0; return FALSE; } return TRUE; }
// 从XML设置菜单位置信息属性 HRESULT CControlBase::OnAttributeMenuPosChange(const CString& strValue, BOOL bLoading) { if (strValue.IsEmpty()) return E_FAIL; m_posMenu.nCount=0; LPCTSTR pszValue=strValue; while(m_posMenu.nCount<4 && pszValue) { pszValue=ParsePosition(pszValue,m_posMenu.Item[m_posMenu.nCount++]); } return bLoading?S_FALSE:S_OK; }
// 从XML设置Tab页签按钮位置信息属性 HRESULT CDuiTabCtrl::OnAttributeTabBtnPosChange(const CString& strValue, BOOL bLoading) { if (strValue.IsEmpty()) return E_FAIL; m_posTabBtn.nCount=0; LPCTSTR pszValue=strValue; while(m_posTabBtn.nCount<4 && pszValue) { pszValue=ParsePosition(pszValue,m_posTabBtn.Item[m_posTabBtn.nCount++]); } return bLoading?S_FALSE:S_OK; }
/** * @bug 4134203 * SimpleDateFormat won't parse "GMT" */ void DateFormatRegressionTest::Test4134203(void) { UErrorCode status = U_ZERO_ERROR; UnicodeString dateFormat = "MM/dd/yy HH:mm:ss zzz"; SimpleDateFormat *fmt = new SimpleDateFormat(dateFormat, status); if (failure(status, "new SimpleDateFormat", TRUE)) return; ParsePosition p0(0); UDate d = fmt->parse("01/22/92 04:52:00 GMT", p0); logln(dateToString(d)); if(p0 == ParsePosition(0)) errln("Fail: failed to parse 'GMT'"); // In the failure case an exception is thrown by parse(); // if no exception is thrown, the test passes. delete fmt; }
// 重载加载XML节点函数,加载下层的div内容 BOOL CDuiLayout::Load(DuiXmlNode pXmlElem, BOOL bLoadSubControl) { __super::Load(pXmlElem); if(pXmlElem == NULL) { return FALSE; } // 加载下层的div节点信息 for (DuiXmlNode pDivElem = pXmlElem.child(_T("layout-div")); pDivElem; pDivElem=pDivElem.next_sibling(_T("layout-div"))) { CString strDivPos = pDivElem.attribute(_T("div-pos")).value(); int nMinPos = _ttoi(pDivElem.attribute(_T("min-pos")).value()); int nMaxPos = _ttoi(pDivElem.attribute(_T("max-pos")).value()); // 创建div CDuiPanel* pControlPanel = (CDuiPanel*)DuiSystem::CreateControlByName(_T("div"), m_hWnd, this); m_vecControl.push_back(pControlPanel); // 加载XML中Tab节点的各个下层控件节点 pControlPanel->Load(pDivElem); LayoutItemInfo itemInfo; itemInfo.pControlPanel = pControlPanel; ParsePosition(strDivPos, itemInfo.pos); // 解析pos信息 itemInfo.nMinPos = nMinPos; itemInfo.nMaxPos = nMaxPos; itemInfo.nPos = -1; // 初始化实际的位置值 itemInfo.rcSplit = CRect(0, 0, 0, 0); // 初始化分割线区域 itemInfo.rcThumb = CRect(0, 0, 0, 0); // 初始化滑块区域 m_vecItemInfo.push_back(itemInfo); } // 初始化div中控件的位置 SetRect(m_rc); m_bInit = TRUE; return TRUE; }
void BoardConfigurationSerializer::LoadBoard(BoardConfiguration* board, const std::string& file) { if (board == nullptr) return; board->Clear(); //TODO: Add some error detection here. If the config file is malformed, random stuff (most probably crash) happens. boost::property_tree::ptree configTree; boost::property_tree::json_parser::read_json(file, configTree); for (auto& value : configTree.get_child("board")) { Player player = ParsePlayer(value.second.get<std::string>("player")); ChessPiece::Type pieceType = ParseType(value.second.get<std::string>("type")); char xPos = value.second.get<char>("x"); unsigned int yPos = value.second.get<unsigned int>("y"); board->m_BitBoards[player][pieceType] |= (uint64_t)1 << ParsePosition(xPos, yPos); } board->m_CurrentPlayer = ParsePlayer(configTree.get<std::string>("currentPlayer")); }
ModelData* ModelLoader::LoadModelFile(std::string filePath) { ifstream file; file.open(filePath + ".obj"); if (!file) return 0; string str; while (!file.eof()) { file >> str; if (str == "#" || str == "s") ParseComment(file); else if (str == "v") ParsePosition(file); //position else if (str == "vn") ParseNormal(file); //normal else if (str == "vt") ParseTexCoord(file); //texturkoordinat else if (str == "f") ParseFace(file); //face else if (str == "usemtl") ParseMaterial(file); //material else if (str == "g") ParseGroup(file); //group else if (str == "mtllib") //materialfile { ParseMaterialFile(file, filePath); } str = ""; } //ParseFace2(file); ModelData* model = new ModelData(); for (auto it = m_groups.begin(); it != m_groups.end(); ++it) model->Groups.push_back(it->second); return model; }
// 从XML设置位置信息属性 HRESULT CControlBase::OnAttributePosChange(const CStringA& strValue, BOOL bLoading) { if (strValue.IsEmpty()) return E_FAIL; m_strPos = strValue; DUIDLG_POSITION dlgpos; dlgpos.nCount=0; LPCSTR pszValue=strValue; while(dlgpos.nCount<4 && pszValue) { pszValue=ParsePosition(pszValue,dlgpos.Item[dlgpos.nCount++]); } if (2 == dlgpos.nCount || 4 == dlgpos.nCount) { if(4 == dlgpos.nCount) { CRect rectParent = CRect(0,0,0,0); CDuiObject* pParent = GetParent(); if(pParent) { rectParent = pParent->GetRect(); } CRect rect; rect.left = PositionItem2Value(dlgpos.Left, rectParent.left, rectParent.right); rect.top = PositionItem2Value(dlgpos.Top, rectParent.top, rectParent.bottom); rect.right = PositionItem2Value(dlgpos.Right, rectParent.left, rectParent.right); rect.bottom = PositionItem2Value(dlgpos.Bottom, rectParent.top, rectParent.bottom); SetRect(rect); } else if(2 == dlgpos.nCount) { //m_uPositionType = (m_uPositionType & ~SizeX_Mask) | SizeX_FitContent; //m_uPositionType = (m_uPositionType & ~SizeY_Mask) | SizeY_FitContent; CRect rectParent = CRect(0,0,0,0); CDuiObject* pParent = GetParent(); if(pParent) { rectParent = pParent->GetRect(); } CRect rect; rect.left = PositionItem2Value(dlgpos.Left, rectParent.left, rectParent.right); rect.top = PositionItem2Value(dlgpos.Top, rectParent.top, rectParent.bottom); if(m_nWidth != 0) { rect.right = rect.left + m_nWidth; }else { rect.right = PositionItem2Value(dlgpos.Left, rectParent.left, rectParent.right); } if(m_nHeight != 0) { rect.bottom = rect.top + m_nHeight; }else { rect.bottom = PositionItem2Value(dlgpos.Top, rectParent.top, rectParent.bottom); } SetRect(rect); } } else dlgpos.nCount = 0; return bLoading?S_FALSE:S_OK; }
void UciLoop(void) { char command[4096], token[180], *ptr; POS p[1]; setbuf(stdin, NULL); setbuf(stdout, NULL); SetPosition(p, START_POS); AllocTrans(16); for (;;) { ReadLine(command, sizeof(command)); ptr = ParseToken(command, token); // checks if Rodent should play with an opening book // UseBook remains for backward compatibly if ((strstr(command, "setoption name OwnBook value")) || (strstr(command, "setoption name UseBook value"))) use_book = (strstr(command, "value true") != 0); if (strstr(command, "setoption name UCI_LimitStrength value")) Param.fl_weakening = (strstr(command, "value true") != 0); if (strcmp(token, "uci") == 0) { printf("id name %s\n", PROG_NAME); printf("id author Pawel Koziol (based on Sungorus 1.4 by Pablo Vazquez)\n"); printf("option name Hash type spin default 16 min 1 max 4096\n"); printf("option name Clear Hash type button\n"); if (panel_style > 0) { printf("option name PawnValue type spin default %d min 0 max 1200\n", Param.pc_value[P]); printf("option name KnightValue type spin default %d min 0 max 1200\n", Param.pc_value[N]); printf("option name BishopValue type spin default %d min 0 max 1200\n", Param.pc_value[B]); printf("option name RookValue type spin default %d min 0 max 1200\n", Param.pc_value[R]); printf("option name QueenValue type spin default %d min 0 max 1200\n", Param.pc_value[Q]); printf("option name KeepPawn type spin default %d min -200 max 200\n", Param.keep_pc[P]); printf("option name KeepKnight type spin default %d min -200 max 200\n", Param.keep_pc[N]); printf("option name KeepBishop type spin default %d min -200 max 200\n", Param.keep_pc[B]); printf("option name KeepRook type spin default %d min -200 max 200\n", Param.keep_pc[R]); printf("option name KeepQueen type spin default %d min -200 max 200\n", Param.keep_pc[Q]); printf("option name BishopPair type spin default %d min -100 max 100\n", Param.bish_pair); if (panel_style == 2) printf("option name KnightPair type spin default %d min -100 max 100\n", Param.knight_pair); printf("option name ExchangeImbalance type spin default %d min -100 max 100\n", Param.exchange_imbalance); printf("option name KnightLikesClosed type spin default %d min 0 max 10\n", Param.np_bonus); if (panel_style == 2) printf("option name RookLikesOpen type spin default %d min 0 max 10\n", Param.rp_malus); printf("option name Material type spin default %d min 0 max 500\n", Param.mat_perc); printf("option name OwnAttack type spin default %d min 0 max 500\n", dyn_weights[DF_OWN_ATT]); printf("option name OppAttack type spin default %d min 0 max 500\n", dyn_weights[DF_OPP_ATT]); printf("option name OwnMobility type spin default %d min 0 max 500\n", dyn_weights[DF_OWN_MOB]); printf("option name OppMobility type spin default %d min 0 max 500\n", dyn_weights[DF_OPP_MOB]); printf("option name KingTropism type spin default %d min -50 max 500\n", weights[F_TROPISM]); printf("option name PiecePlacement type spin default %d min 0 max 500\n", Param.pst_perc); printf("option name PiecePressure type spin default %d min 0 max 500\n", weights[F_PRESSURE]); printf("option name PassedPawns type spin default %d min 0 max 500\n", weights[F_PASSERS]); printf("option name PawnStructure type spin default %d min 0 max 500\n", weights[F_PAWNS]); printf("option name Outposts type spin default %d min 0 max 500\n", weights[F_OUTPOST]); printf("option name Lines type spin default %d min 0 max 500\n", weights[F_LINES]); if (panel_style == 2) { printf("option name PawnShield type spin default %d min 0 max 500\n", Param.shield_perc); printf("option name PawnStorm type spin default %d min 0 max 500\n", Param.storm_perc); } printf("option name PstStyle type spin default %d min 0 max 2\n", Param.pst_style); printf("option name MobilityStyle type spin default %d min 0 max 1\n", Param.mob_style); if (panel_style == 2) { printf("option name DoubledPawnMg type spin default %d min -100 max 0\n", Param.doubled_malus_mg); printf("option name DoubledPawnEg type spin default %d min -100 max 0\n", Param.doubled_malus_eg); printf("option name IsolatedPawnMg type spin default %d min -100 max 0\n", Param.isolated_malus_mg); printf("option name IsolatedPawnEg type spin default %d min -100 max 0\n", Param.isolated_malus_eg); printf("option name IsolatedOnOpenMg type spin default %d min -100 max 0\n", Param.isolated_open_malus); printf("option name BackwardPawnMg type spin default %d min -100 max 0\n", Param.backward_malus_base); printf("option name BackwardPawnEg type spin default %d min -100 max 0\n", Param.backward_malus_eg); printf("option name BackwardOnOpenMg type spin default %d min -100 max 0\n", Param.backward_open_malus); } // Strength settings - we use either Elo slider with an approximate formula // or separate options for nodes per second reduction and eval blur if (fl_elo_slider == 0) { printf("option name NpsLimit type spin default %d min 0 max 5000000\n", Timer.nps_limit); printf("option name EvalBlur type spin default %d min 0 max 5000000\n", Param.eval_blur); } else { printf("option name UCI_LimitStrength type check default false\n"); printf("option name UCI_Elo type spin default %d min 800 max 2800\n", Param.elo); } printf("option name Contempt type spin default %d min -250 max 250\n", Param.draw_score); printf("option name SlowMover type spin default %d min 10 max 500\n", time_percentage); printf("option name Selectivity type spin default %d min 0 max 200\n", hist_perc); printf("option name OwnBook type check default true\n"); printf("option name GuideBookFile type string default guide.bin\n"); printf("option name MainBookFile type string default rodent.bin\n"); printf("option name BookFilter type spin default %d min 0 max 5000000\n", Param.book_filter); } if (panel_style == 0) { printf("option name PersonalityFile type string default rodent.txt\n"); printf("option name OwnBook type check default true\n"); if (fl_separate_books) { printf("option name GuideBookFile type string default guide.bin\n"); printf("option name MainBookFile type string default rodent.bin\n"); } } printf("uciok\n"); } else if (strcmp(token, "isready") == 0) { printf("readyok\n"); } else if (strcmp(token, "setoption") == 0) { ParseSetoption(ptr); } else if (strcmp(token, "position") == 0) { ParsePosition(p, ptr); } else if (strcmp(token, "perft") == 0) { ptr = ParseToken(ptr, token); int depth = atoi(token); if (depth == 0) depth = 5; Timer.SetStartTime(); nodes = Perft(p, 0, depth); #if defined _WIN32 || defined _WIN64 printf (" perft %d : %I64d nodes in %d miliseconds\n", depth, nodes, Timer.GetElapsedTime() ); #else printf(" perft %d : %lld nodes in %d miliseconds\n", depth, nodes, Timer.GetElapsedTime()); #endif } else if (strcmp(token, "print") == 0) { PrintBoard(p); } else if (strcmp(token, "eval") == 0) { SetAsymmetricEval(p->side); Eval.Print(p); } else if (strcmp(token, "step") == 0) { ParseMoves(p, ptr); } else if (strcmp(token, "go") == 0) { ParseGo(p, ptr); } else if (strcmp(token, "bench") == 0) { ptr = ParseToken(ptr, token); Bench(atoi(token)); } else if (strcmp(token, "quit") == 0) { return; } } }
void C4Shader::AddSlices(ShaderSliceList& slices, const char *szWhat, const char *szText, const char *szSource, int iSourceTime) { const char *pStart = szText, *pPos = szText; int iDepth = -1; int iPosition = -1; bool fGotContent = false; // Anything in the slice apart from comments and white-space? // Find slices while(*pPos) { // Comment? Might seem silly, but we don't want to get confused by braces in comments... if (*pPos == '/' && *(pPos + 1) == '/') { pPos += 2; while (*pPos && *pPos != '\n') pPos++; continue; } if (*pPos == '/' && *(pPos + 1) == '*') { pPos += 2; while (*pPos && (*pPos != '*' || *(pPos+1) != '/')) pPos++; if (*pPos) pPos += 2; continue; } // Opening brace? if (*pPos == '{') { iDepth++; pPos++; continue; } if (*pPos == '}') { // End of slice? if (iPosition != -1 && !iDepth) { // Have a new slice! if (fGotContent) { StdStrBuf Str; Str.Copy(pStart, pPos - pStart); AddSlice(slices, iPosition, Str.getData(), szSource, iSourceTime); } iPosition = -1; pStart = pPos+1; fGotContent = false; } if (iDepth >= 0) iDepth--; pPos++; continue; } // New slice? We need a newline followed by "slice". Don't do // the depth check, so that we also recognize slices inside // an ifdefed-out "void main() {" block. if (*pPos == '\n') { if (SEqual2(pPos+1, "slice") && !isalnum(*(pPos+6))) { const char *pSliceEnd = pPos; pPos += 6; while(isspace(*pPos)) pPos++; if(*pPos != '(') { pPos++; continue; } pPos++; // Now let's parse the position iPosition = ParsePosition(szWhat, &pPos); if (iPosition != -1) { // Make sure a closing parenthesis while(isspace(*pPos)) pPos++; if(*pPos != ')') { pPos++; continue; } pPos++; // Make sure an opening brace follows while(isspace(*pPos)) pPos++; if (*pPos == '{') { // Add code before "slice" as new slice if (fGotContent) { StdStrBuf Str; Str.Copy(pStart, pSliceEnd - pStart); AddSlice(slices, -1, Str.getData(), szSource, iSourceTime); } iDepth = 0; pStart = pPos+1; fGotContent = false; } else { ShaderLogF(" gl: Missing opening brace in %s!", szWhat); } pPos++; continue; } } } // Otherwise: Continue if (!isspace(*pPos)) fGotContent = true; pPos++; } // Add final slice if (fGotContent) { StdStrBuf Str; Str.Copy(pStart, pPos - pStart); AddSlice(slices, iPosition, Str.getData(), szSource, iSourceTime); } }