Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

556 lines
14 KiB

  1. //-----------------------------------------------------------------------------
  2. //
  3. // File: locstr.inl
  4. // Copyright (C) 1994-1997 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // Inline functions for the CLocString object. This file is included by
  8. // locstr.h, and should never be used directly.
  9. //
  10. // Owner: MHotchin
  11. //
  12. //-----------------------------------------------------------------------------
  13. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  14. //
  15. // Return the 'generic' type of the string.
  16. //
  17. //-----------------------------------------------------------------------------
  18. inline
  19. CST::StringType
  20. CLocString::GetStringType(void)
  21. const
  22. {
  23. if (!m_pasBaseString.IsNull())
  24. {
  25. return m_stStringType;
  26. }
  27. else
  28. {
  29. return CST::None;
  30. }
  31. }
  32. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  33. //
  34. // Returns the 'Base' string. This is the localizable string,
  35. // It is the part that weighs most heavily in auto-translation.
  36. //
  37. //-----------------------------------------------------------------------------
  38. inline
  39. const CPascalString &
  40. CLocString::GetString(void)
  41. const
  42. {
  43. return m_pasBaseString;
  44. }
  45. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  46. //
  47. // Get the code page type for the string.
  48. //
  49. //-----------------------------------------------------------------------------
  50. inline
  51. CodePageType
  52. CLocString::GetCodePageType(void)
  53. const
  54. {
  55. return m_cptCodePageType;
  56. }
  57. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  58. //
  59. // TODO - comment this function
  60. //
  61. //-----------------------------------------------------------------------------
  62. inline
  63. const CPascalString &
  64. CLocString::GetNote(void)
  65. const
  66. {
  67. return m_pstrNote;
  68. }
  69. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  70. //
  71. // Sets the string type. The parser and database are the only people who
  72. // should be setting this.
  73. //
  74. //-----------------------------------------------------------------------------
  75. inline
  76. void
  77. CLocString::SetStringType(
  78. CST::StringType newType)
  79. {
  80. m_stStringType = newType;
  81. }
  82. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  83. //
  84. // Sets the 'Base' string.
  85. //
  86. // This method can throw the following exceptions:
  87. // CMemoryException
  88. //
  89. //-----------------------------------------------------------------------------
  90. inline
  91. void
  92. CLocString::SetString(
  93. const CPascalString &pstrNewBaseString)
  94. {
  95. m_pasBaseString = pstrNewBaseString;
  96. }
  97. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  98. //
  99. // Sets the code page type for the string.
  100. //
  101. //-----------------------------------------------------------------------------
  102. inline
  103. void
  104. CLocString::SetCodePageType(
  105. CodePageType cptNew)
  106. {
  107. m_cptCodePageType = cptNew;
  108. }
  109. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  110. //
  111. // Clears out the hot-key to an uninitialized state.
  112. //
  113. //-----------------------------------------------------------------------------
  114. inline
  115. void
  116. CLocString::ClearHotKey(void)
  117. {
  118. m_wchHotKeyChar = L'\0';
  119. m_uiHotKeyPos = 0;
  120. }
  121. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  122. //
  123. // TODO - comment this function
  124. //
  125. //-----------------------------------------------------------------------------
  126. inline
  127. void
  128. CLocString::SetNote(
  129. const CPascalString &pstrNote)
  130. {
  131. m_pstrNote = pstrNote;
  132. }
  133. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  134. //
  135. // See if the hotkey has any info in it. Checks to see if the hotkey is
  136. // a valid character (ie non-zero).
  137. //
  138. //-----------------------------------------------------------------------------
  139. inline
  140. BOOL // TRUE if it contains a hotkey
  141. CLocString::HasHotKey(void)
  142. const
  143. {
  144. return (m_wchHotKeyChar != L'\0');
  145. }
  146. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  147. //
  148. // Returns the hot-key character. If the hot-key is not initialized, this
  149. // returns NUL.
  150. //
  151. //-----------------------------------------------------------------------------
  152. inline
  153. WCHAR // Hot key character.
  154. CLocString::GetHotKeyChar(void)
  155. const
  156. {
  157. return m_wchHotKeyChar;
  158. }
  159. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  160. //
  161. // Returns the hot-key position. Interpretationb of the position is left up
  162. // to the caller. If the hot-key is uninitialized, this returns 0.
  163. //
  164. //-----------------------------------------------------------------------------
  165. inline
  166. UINT // Position of the hot key.
  167. CLocString::GetHotKeyPos(void)
  168. const
  169. {
  170. return m_uiHotKeyPos;
  171. }
  172. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  173. //
  174. // Sets the hot-key character
  175. //
  176. //-----------------------------------------------------------------------------
  177. inline
  178. void
  179. CLocString::SetHotKeyChar(
  180. WCHAR wchNewHotKeyChar) // Character to set as hot key.
  181. {
  182. m_wchHotKeyChar = wchNewHotKeyChar;
  183. }
  184. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  185. //
  186. // Sets the position of the hot-key
  187. //
  188. //-----------------------------------------------------------------------------
  189. inline
  190. void
  191. CLocString::SetHotKeyPos(
  192. UINT uiNewHotKeyPos) // Position for the hot-key.
  193. {
  194. m_uiHotKeyPos = uiNewHotKeyPos;
  195. }
  196. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  197. //
  198. // Assignment operator for LocStrings.
  199. //
  200. //-----------------------------------------------------------------------------
  201. inline
  202. const CLocString &
  203. CLocString::operator=(
  204. const CLocString &lsSource)
  205. {
  206. CopyLocString(lsSource);
  207. return *this;
  208. }
  209. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  210. //
  211. // Operator == version of IsEqualTo
  212. //
  213. //-----------------------------------------------------------------------------
  214. inline
  215. int // TRUE (1) if equal
  216. CLocString::operator==(
  217. const CLocString &lsOtherString) // String to compare
  218. const
  219. {
  220. return ((((HasHotKey() && lsOtherString.HasHotKey()) &&
  221. (GetHotKeyChar() == lsOtherString.GetHotKeyChar()) &&
  222. (GetHotKeyPos() == lsOtherString.GetHotKeyPos())) ||
  223. (!HasHotKey() && !lsOtherString.HasHotKey())) &&
  224. m_pasBaseString == lsOtherString.m_pasBaseString);
  225. }
  226. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  227. //
  228. // Operator == version of IsEqualTo
  229. //
  230. //-----------------------------------------------------------------------------
  231. inline
  232. int // TRUE (1) if equal
  233. CLocString::operator!=(
  234. const CLocString &lsOtherString) // String to compare
  235. const
  236. {
  237. return !(operator==(lsOtherString));
  238. }
  239. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  240. //
  241. // Constructor for the Translation Object. Just sets the components to
  242. // default bad values.
  243. //
  244. //-----------------------------------------------------------------------------
  245. inline
  246. CLocTranslation::CLocTranslation()
  247. {
  248. m_lidSource = BAD_LOCALE;
  249. m_lidTarget = BAD_LOCALE;
  250. m_uiRanking = 0;
  251. }
  252. //-----------------------------------------------------------------------------
  253. //
  254. // Implementation for copying a translation.
  255. //
  256. //-----------------------------------------------------------------------------
  257. inline
  258. void
  259. CLocTranslation::CopyTranslation(
  260. const CLocTranslation &Source)
  261. {
  262. m_lsSource = Source.m_lsSource;
  263. m_lidSource = Source.m_lidSource;
  264. m_lsTarget = Source.m_lsTarget;
  265. m_lidTarget = Source.m_lidTarget;
  266. m_pstrGlossaryNote = Source.m_pstrGlossaryNote;
  267. m_uiRanking = Source.m_uiRanking;
  268. }
  269. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  270. //
  271. // Copy constructor for a CLocTranslation
  272. //
  273. //-----------------------------------------------------------------------------
  274. inline
  275. CLocTranslation::CLocTranslation(
  276. const CLocTranslation &Source)
  277. {
  278. CopyTranslation(Source);
  279. }
  280. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  281. //
  282. // Sets all the required components of a translation.
  283. //
  284. //-----------------------------------------------------------------------------
  285. inline
  286. void
  287. CLocTranslation::SetTranslation(
  288. const CLocString &Source,
  289. LangId lidSource,
  290. const CLocString &Target,
  291. LangId lidTarget)
  292. {
  293. m_lsSource = Source;
  294. m_lidSource = lidSource;
  295. m_lsTarget = Target;
  296. m_lidTarget = lidTarget;
  297. }
  298. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  299. //
  300. // Sets the glossary note for the translation.
  301. //
  302. //-----------------------------------------------------------------------------
  303. inline
  304. void
  305. CLocTranslation::SetNote(
  306. const CPascalString &pstrNote)
  307. {
  308. m_pstrGlossaryNote = pstrNote;
  309. }
  310. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  311. //
  312. // Constructor for the translation that takes all the required info.
  313. //
  314. //-----------------------------------------------------------------------------
  315. inline
  316. CLocTranslation::CLocTranslation(
  317. const CLocString &Source,
  318. LangId lidSource,
  319. const CLocString &Target,
  320. LangId lidTarget)
  321. {
  322. SetTranslation(Source, lidSource, Target, lidTarget);
  323. }
  324. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  325. //
  326. // Operator == version of IsEqualTo
  327. //
  328. //-----------------------------------------------------------------------------
  329. inline
  330. int
  331. CLocTranslation::operator==(const CLocTranslation &locTran) const
  332. {
  333. return (
  334. GetSourceString() == locTran.GetSourceString()
  335. && GetSourceString().GetStringType()
  336. == locTran.GetSourceString().GetStringType()
  337. && GetTargetString() == locTran.GetTargetString()
  338. && GetTargetString().GetStringType()
  339. == locTran.GetTargetString().GetStringType()
  340. && GetNote() == locTran.GetNote()
  341. && GetRanking() == locTran.GetRanking()
  342. );
  343. }
  344. inline
  345. int
  346. CLocTranslation::operator!=(const CLocTranslation &locTran) const
  347. {
  348. return !(operator==(locTran));
  349. }
  350. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  351. //
  352. // Returns the source string of the translation.
  353. //
  354. //-----------------------------------------------------------------------------
  355. inline
  356. const CLocString &
  357. CLocTranslation::GetSourceString(void)
  358. const
  359. {
  360. return m_lsSource;
  361. }
  362. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  363. //
  364. // Returns the target string for the translation.
  365. //
  366. //-----------------------------------------------------------------------------
  367. inline
  368. const CLocString &
  369. CLocTranslation::GetTargetString(void)
  370. const
  371. {
  372. return m_lsTarget;
  373. }
  374. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  375. //
  376. // Returns the glkossary note for the translation.
  377. //
  378. //-----------------------------------------------------------------------------
  379. inline
  380. const CPascalString &
  381. CLocTranslation::GetNote(void)
  382. const
  383. {
  384. return m_pstrGlossaryNote;
  385. }
  386. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  387. //
  388. // Returns the translation ranking for the strnslation. See
  389. // CalculateRanking().
  390. //
  391. //-----------------------------------------------------------------------------
  392. inline
  393. UINT
  394. CLocTranslation::GetRanking(void)
  395. const
  396. {
  397. return m_uiRanking;
  398. }
  399. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  400. //
  401. // Returns the embedded source language for the translation.
  402. //
  403. //-----------------------------------------------------------------------------
  404. inline
  405. LangId
  406. CLocTranslation::GetSourceLanguage(void)
  407. const
  408. {
  409. return m_lidSource;
  410. }
  411. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  412. //
  413. // Returns the embedded target language for the translation.
  414. //
  415. //-----------------------------------------------------------------------------
  416. inline
  417. LangId
  418. CLocTranslation::GetTargetLanguage(void)
  419. const
  420. {
  421. return m_lidTarget;
  422. }
  423. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  424. //
  425. // Validates the translation. This make sure that all the needed components
  426. // of tghe source string exist in some form in the target string. This
  427. // simply returns a validation code.
  428. //
  429. //-----------------------------------------------------------------------------
  430. inline
  431. CVC::ValidationCode
  432. CLocTranslation::ValidateTranslation(
  433. const CValidationOptions &Options)
  434. const
  435. {
  436. CLString str;
  437. return ValidateTranslation(Options, FALSE, str, NULL, NULL);
  438. }
  439. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  440. //
  441. // Assignment operator for the translation object.
  442. //
  443. //-----------------------------------------------------------------------------
  444. inline
  445. const CLocTranslation &
  446. CLocTranslation::operator=(
  447. const CLocTranslation &Source) // Translation to copy from.
  448. {
  449. CopyTranslation(Source);
  450. return *this;
  451. }
  452. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  453. //
  454. // Destructor for the translation. Nothing interesting happens here.
  455. //
  456. //-----------------------------------------------------------------------------
  457. inline
  458. CLocTranslation::~CLocTranslation()
  459. {
  460. DEBUGONLY(AssertValid());
  461. }